1. Which of the following are the java keywords?
A) delete
B) Abstract
C) Long
D) static
2. What will be printed when you execute this code?
class A
{
A()
{
System.out.println("Class A Constructor ");
}
}
public class B extends A
{
B()
{
System.out.println("Class B Constructor ");
}
public static void main(String args[])
{
B b = new B();
}
}
A) "Class A Constructor" followed by "Class B Constructor"
B) "Class B Constructor" followed by "Class A Constructor"
C) Compile time error
D) Run time error
3. which of the statements are true?
A) Overridden methods have the same method name and signature
B) Overloaded methods have the same method name and signature
C) Overridden methods have the same method name and different signature
D) Overloaded methods have the different method name and different signature
4.What is the output when you execute the following code?
int i = 100;
switch (i)
{
case 100:
System.out.println(i);
case 200:
System.out.println(i);
case 300:
System.out.println(i);
A) Nothing is printed
B) Compile time error
C) The values 100,100,100 printed
D) Only 100 is printed
5. From the following code how many objects are garbage collected?
String string1 = "Test";
String string2 = "Today";
string1 = null;
string1 = string2;
A) 1
B) 2
C) 3
D) 0
6. Which of the following class definitions are legal declaration of an abstract class?
A) class A { abstract void Method() {} }
B) abstract class A { void Method() ; }
C) class A { abstract void Method() {System.out.println("Test");} }
D) class abstract A { abstract void Method() {} }
7.What is the result of compiling the following code?
public class Exec
{
public static void main(String args[])
{
int value;
value = value + 1;
System.out.println(" The value is : " + value);
}
}
A) Compile and runs with no output
B) Compiles and runs printing out "The value is 1"
C) Does not compile because of error
D) Compiles but generates run time error
8. What is the output of the following code?
public class Exec
{
public static void main(String args[])
{
String s[] = new String[6];
System.out.print(s[6]);
}
}
A) A null is printed
B) nothing is printed
C) Exception is thrown
D) null followed by 0 is printed on the screen
9. Which of the following assignment statements is invalid?
A) long l = 698.65;
B) float f = 55.8F;
C) double d = 0x45876;
D) All of the above
10. Which of the following are correct, if you compile the following code?
import java.awt.*;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;
public class Exec extends Frame implements WindowListener
{
public Exec()
{
addWindowListener(this); // This is listener registration
setSize(300, 300);
setVisible(true);
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public static void main(String args[])
{
Exec CW = new Exec();
}
}
A) Compile time error
B) Run time error
C) Code compiles but Frames does not listen to WindowEvents
D) Compile and runs successfully.
11. The statement X %= 5, can best described as?
A) A equals a divided by 5;
B) A equals A in 5 digit percentage form
C) A equals A modulus 5.
D) None of the above
12. What will happen when you attempt to compile and run the following code?
public class Exec
{
public static void main(String args[])
{
String s1 = new String("Test One");
String s2 = new String("Test One");
if (s1 == s2)
{
System.out.println("Both are equal");
}
Boolean b = new Boolean(true);
Boolean b1 = new Boolean(false);
if (b.equals(b1))
{
System.out.println("These wrappers are equal ");
}
}
}
A) Compile time error
B) Runtime error.
C) No output
D) "These wrappers are equal"
13. What is the result when you try to compile the following code?
public class Exec
{
public static void main(String args[])
{
String s = "HelloWorld";
if ( (s != null) && (s.length() > 6))
System.out.println("The value of s is " + s);
}
}
A) Compile time error
B) Runtime error
C) No output is printed
D) "The value of s is HelloWorld" is printed on the screen
14. How can you implement encapsulation.
A) By making methods private and variable private
B) By making methods are public and variables as private
C) Make all variable are public and access them using methods
D) Making all methods and variables as protected.
15. Given the following class definition, which of the following methods could be legally placed after the comment ?
public class Exec
{
public void amethod(int i, String s)
{}
//Here
}
A) public void amethod(String s, int i){}
B) public int amethod(int i, String s){}
C) public void amethod(int i, String mystring){}
D) public void amethod(int i, String s){}
16. Given the following class definition which of the following can be legally placed after the comment line?
class Base
{
public Base(int i)
{}
}
public class Exec
extends Base
{
public static void main(String arg[])
{
Exec d = new Exec(10);
}
Exec(int i)
{
super(i);
}
Exec(String s, int i)
{
this(i);
//Here
}
}
A) Exec d = new Exec();
B) super();
C) this("Hello",10);
D) Base b = new Base(10);
17. Which of the following statements are true about the fragment below?
import java.lang.Math;
public class Exec
{
public static void main(String args[])
{
Math m = new Math();
System.out.println(m.abs(2.6));
}
}
A) Compiler fails at line: import java.lang.Math;
B) Compiler fails at line: Math m = new Math();
C) Compiler fails at the time of Math class instantiation
D) Compiler succeeds.
18. What will be the output of the following line?
public class Exec
{
public static void main(String args[])
{
System.out.println(Math.floor(145.1));
System.out.println(Math.ceil( -145.4));
}
}
A) 145.0 followed by -145.0
B) 150.0 followed by -150.0
C) 145.1 followed by -145.4
B) 150 followed by -150
19.Which of the following prints "Equal"
A) int a = 10;
float f = 10;
if (a == f)
{
System.out.println("Equal");
}
B) Integer i = new Integer(10);Double d = new Double(10);if ( i = =d){ System.out.println("Equal");}
C) Integer a = new Integer(10);int b = 10;if ( a = = b){ System.out.println("Equal");}
D) String a = new String("10");
String b = new String("10");
if (a == b)
{
System.out.println("Equal");
}
20. If you run the following code on a PC from the directory c:\source:
import java.io.*;
class Exec
{
public static void main(String[] args) throws Exception
{
File file = new File("Ran.test");
System.out.println(file.getAbsolutePath());
}
}
What do you expect the output to be?
A) Ran.test
B) source\Ran.test
C) c:\source\Ran.test
D) c:\source
[此贴子已经被作者于2010-12-12 08:25:48编辑过]