java programming MCQs answers required,
May 30, 2010 at 11:54 AM
java MCQs
The keyword this is used to 1. Invoke constructor of the another class 2. Invoke alternate constructor of the same class 3. Invoke constructor of super class form sub class 4. Invoke constructor of sub class from supper class Which of the following syntax attaches on output stream to console? 1. FileWriter fw=newFileWriter[output.text] 2. FileWriter fw=newFileWriter[fileDescription.out] 3. FileWriter fw=newFileWriter[fileDescriptio.in] 4. FileWriter fw=newFileWriter[fileDesciptor] What will happen if main method is declared as private? 1. The program does not compile 2. The program throws an exception at runtime 3. The program complies and runs successfully 4. Non of given What will happen if static modifier is removed from the signature of main method? 1. The program does not compile 2. The program compile and runs successfully 3. The program compile but does not run 4. Non of given Which of the following methods are invoked by the AWT to support paint and repaint operations? ► paint( ) ► repaint( ) ► draw( ) ► redraw( ) When defining a method you must include a ___________ to declare any exception that might be thrown but is not caught in the method. ► try block ► finally block ► catch block ► throws-clause Aside from the Scanner class, which of the following classes can be used for text-file file input? ► ObjectInputStream ► BufferedReader ► StringTokenizer ► None of these Which of the following statements is true regarding Vectors with no specified base type? ► A base type is needed, because Java needs to know how to allocate memory. ► No base type is needed, because Java will use the Object class as a base type. ► If a base type is not specified the code will not compile. ► No base type is needed because Vectors default to storing String objects. A serializable class must implement the method(s) _________. ► readObject and writeObject ► Either readObject or writeObject, or both, depending upon the desired behavior ► No need to implement any method ► None of the given option Which of the following are passed as an argument to the paint ( ) method? ► A Canvas object ► A Graphics object ► An Image object ► A paint object The code below draws a line. What color is the line? g.setColor(Color.red.green.yellow.red); g.drawLine(0, 0, 100,100); ► Red ► Green ► Yellow What if the static modifier is removed from the signature of the main method? ► The program does not compile ► The program compiles but does not run ► The program compiles and runs properly ► The program throws an exception on compile time What if the main method is declared as private? ► The program does not compile ► The program compiles but does not run ► The program compiles and runs properly ► The program throws an exception on compile time A member variable or method prefixed by the protected access modifier can be accessed: ► Within the same class ► Within the sub-class ► Within the same package ► All of the above Which of the following is modifier is provided by default if no access is written explicitly? 1. public 2. Private 3. Protected 4. Default This is used to ________ 1. Invokes constructor of another class 2. Invokes alternate constructor from same class 3. Invokes constructor of super class from sub class 4. Invokes constructor of sub class from super class In Java a final class must be sub-classed before it. True/ False A top level class without any modifier is accessible to 1. any class 2. any class within the same package 3. any class within the same file 4. any subclass of this class A top level class may have only the following access modifier. 1. Package 2. Private 3. Protected 4. Public In Java an abstract class cannot be sub-classed True / False Given a one dimensional array arr, what is the correct way of getting the number of elements in arr 1. arr.length 2. arr.length – 1 3. arr.size – 1 4. arr.length() When recursive method is called to solve a problem, the method actually is capable of solving only the simpler case(s), or base case(s). True / False Which of these are valid declarations for the main method? 1. public void main(); 2. public static void main(String args[]); 3. static public void main(String); 4. public static int main(String args[]); Map interface is derived from the Collection interface. True / False In Java, which of these classes implement the LayoutManager interface? 1. RowLayout 2. ColumnLayout 3. GridBagLayout 4. FlowLayoutManager BorderLayout is the default layout manager for a JFrame’s content pane True / False _________ define behavior and ____________ define implementation Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code 4. Source Code