Previous | Home | Next |
publicclassTest { publicstaticvoidmain(Stringargs[]) { classFoo{ publicinti=3; } Objecto=(Object)newFoo(); Foofoo=(Foo)o; System.out.println(“i=“+foo.i); } }
A. i = 3
B. Compilation fails.
C. A ClassCastException is thrown at line 6.
D. A ClassCastException is thrown at line 7.
Output:
A. float[] = new float(3); B. float f2[] = new float[]; C. float[] f1 = new float[3]; D. float f3[] = new float[3]; E. float f5[] = { 1.0f, 2.0f, 2.0f }; F. float f4[] = new float[] { 1.0f. 2.0f. 3.0f};
Output:
B. float f2[] = new float[];
The F. statement is incorrect. The float numbers should be separated with commas and not dots.
int i =1,j =10; do { if(i++> --j) { continue; } } while (i <5); System.out.println(“i = “ +i+ “and j = “+j);
A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 5
D. i = 5 and j = 6
E. i = 6 and j = 6
Output:
class Test { private Demo d; void start() { d = new Demo(); this.takeDemo(d); } void takeDemo(Demo demo) { demo = null; demo = new Demo(); } }
A. After line 5.
B. After line 9.
C. After the start() method completes.
D. When the takeDemo() method completes.
E. When the instance running this code is made eligible for garbage collection.
Output:
.Sun JAVA2 Certification Program Volume 1.0
500 Java Objective Questions and Answer
a) float f=1.3;
b) char c="a";
c) byte b=257;
d) boolean b=null;
e) int i=10;
a) float f=1/3;
b) int i=1/3;
c) float f=1.01;
d) double d=999d;.
a) NULL.
b) new.
c) instanceOf.
d) wend.
a) System.out.println(5+4);
b) int i=2+'3';
c) String s="one"+'Two';
d) byte b=255;
a) The garbage collection algorithm in Java is vendor implemented.
b) The size of primitives is platform dependent.
c) The default type for a numerical literal with decimal component is a float.
d) You can modify the value in an Instance of the Integer class with the setValue method.
a) The creation of a named instance of the File class creates a matching file in the underlying operating system only when the close method is called.
b) The RandomAccessFile class allows you to move directly to any point a file.
c). I/O in Java can only be performed using the Listener classes.
d) The characteristics of an instance of the File class such as the directory separator, depend on the current underlying operating system.
a) The instanceof operator can be used to determine if a reference is an instance of a class, but not an interface.
b) The instanceof operator can be used to determine if a reference is an instance of a particular primitive wrapper class.
c) The instanceof operator will only determine if a reference is an instance of a class immediately above in the hierarchy but no further up the inheritance chain.
d) The instanceof operator can be used to determine if one reference is of the same class as another reference thus.
a) An interface can only contain method and not variables.
b) Interfaces cannot have constructors.
c) A class may extend only one other class and implement only one interface.
d) Interfaces are the Java approach to addressing its lack of multiple inheritance, but require implementing classes to create the functionality of the Interfaces.
a) public class MyCalc extends Math
b) Math.max(5);
c) Math.round(9.99,1);
d)Math.mod(4,10);
a) run
b) start
c) yield
d) stop
a) A byte can represent between -128 to 127.
b) A byte can represent between -127 to 128.
c) A byte can represent between -256 to 256.
d) A char can represent between -2x2 pow 16 2 x2 pow 16 - 1.
class Base{ public void Base(){ System.out.println("Base"); } } public class Inner extends Base{ public static void main(String argv[]){ Inner i=new Inner(); } }
a) Compile time error Base is a keyword.
b) Compilation and no output at runtime.
c) Output of Base.
d) Runtime error Base has no valid constructor.
public static void main(String parm[]) { System.out.println(parm[0]); }
If you attempt to compile the class and run the program as follows
"java myclass hello"
What will happen?
a) Compile time error, main is not correctly defined.
b) Run time error, main is not correctly defined.
c) Compilation and output of java.
d) Compilation and output of hello.
a) If a class has any abstract methods it must be declared abstract itself.
b) All methods in an abstract class must be declared as abstract.
c) When applied to a class, the final modifier means it cannot be sub-classed.
d) transient and volatile are Java modifiers.
a) public static native void amethod(){}
b) public static void amethod(){}
c) private protected void amethod(){}
d) static native void amethod();
a) Constructors cannot have a visibility modifier.
b) Constructors can be marked public and protected, but not private.
c) Constructors can only have a primitive return type.
d) Constructors are not inherited.
class Base{ Base(int i){ System.out.println("Base"); } } class Inner extends Base{ public static void main(String argv[]){ Inner s = new Inner(); } void Inner (){ System.out.println("Inner"); } }
a) Compilation and output of the string "Inner"at runtime.
b) Compile time error.
c) Compilation and no output at runtime.
d) Compilation and output of the string "Base".
a) A static methods do not have access to the implicit variable called this.
b) A static method may be called without creating an instance of its class.
c) A static method may not be overridden to be non-static.
d) A static method may not be overloaded.
(a)
char c='1'; System.out.println(c>>1);
(b)
Integer i=Integer("1"); System.out.println(i>>1);
(c)
int i=1; System.out.println(i<<<1);
(d)
int i=1; System.out.println(i<<1);
a) sizeof
b) main
c) transient
d) volatile
a) The default constructor has a return type of void.
b) The default constructor takes a parameter of void.c) The default constructor takes no parameters.
d) The default constructor is not created if the class has any constructors of its own.
a) All of the variables in an interface are implicitly static.
b) All of the variables in an interface are implicitly final.
c) All of the methods in an interface are implicitly abstract.
d) A method in an interface can access class level variables.
a) The String class is implemented as a char array, elements are addressed using the stringname[] convention.
b) The + operator is overloaded for concatenation for the String class.
c) Strings are a primitive type in Java and the StringBuffer is used as the matching wrapper type.
d) The size of a string can be retrieved using the length property.
a) A method in an interface must not have a body.
b) A class may extend one other class plus at most one interface.
c) A class may extends at most one other class plus implement many interfaces.
d) An class accesses an interface via the keyword uses.
a) The following statement will produce a result of 1.
System.out.println( -1 >>>2);
b) Performing an unsigned left shift (<<<) on a negative number will always produce a negative number result.
c) The following statement will produce a result of zero,
System.out.println(1 >>1);
d) All the Java integral types are signed numbers
Previous | Home | Next |