The main method should be static for the reason None of these It can be executed without creating any instance of the class. It can be accessed by every method or variable without any hindrance. It can be accessed easily by the class loader. TRUE ANSWER : ? YOUR ANSWER : ?
class MyClass{ MyClass(){ System.out.print("one"); } public void myMethod(){ this(); System.out.print("two"); }} public class TestClass{ public static void main(String args[]){ MyClass obj = new MyClass(); obj.myMethod(); }} Compilation Error None of these two one one one Exception one one two TRUE ANSWER : ? YOUR ANSWER : ?
The variables declared in a class for the use of all methods of the class are called None of these reference variables objects instance variables TRUE ANSWER : ? YOUR ANSWER : ?
Which of the following options is the best for generating random integer 0 or 1? (int)(Math.random() + 0.2) (int)(Math.random() + 0.5) (int)Math.random() + 1 (int)Math.random() TRUE ANSWER : ? YOUR ANSWER : ?
The finalize() method is called just prior to An object, variable or method goes out of scope. An object or variable goes out of scope. None of these A variable goes out of scope. Before garbage collection. TRUE ANSWER : ? YOUR ANSWER : ?
Determine output:public class Test{ public static void main(String args[]){ MyClass obj = new MyClass(); obj.val = 1; obj.call(obj); System.out.println(obj.val); }}class MyClass{ public int val; public void call(MyClass ref){ ref.val++; }} 2 Compilation Error None of these 3 1 TRUE ANSWER : ? YOUR ANSWER : ?
class MyClass{int i;int j;public MyClass(int i, int j){this.i = i;this.j = j;}public void call(){System.out.print("One");}}public class Test{public static void main(String args[]){MyClass m = new MyClass(); //line 1m.call(); //line 2}} Compilation succeed but no output. Compilation fails due to an error on line 1 Compilation fails due to an error on line 2 One TRUE ANSWER : ? YOUR ANSWER : ?
What is the output of the above program ?class Num { Num(double x ){ System.out.println( x ) ; } }public class Test extends Num { public static void main(String[] args){ Num num = new Num( 2 ) ; } } 2.0 None of these 0 Compile time error TRUE ANSWER : ? YOUR ANSWER : ?
What is the output for the below code ?1. public class A{2. int add(int i, int j){3. return i+j;4. }5. }6. public class B extends A{7. public static void main(String argv[]){8. short s = 9;9. System.out.println(add(s,6));10. }11.} None of these Compile fail due to error on line no 8 Compile fail due to error on line no 2 Compile fail due to error on line no 9 15 TRUE ANSWER : ? YOUR ANSWER : ?
Determine Output:class A{public static void method(int i){System.out.print("Method 1");}public static int method(String str){System.out.print("Method 2");return 0;}}public class Test{ public static void main(String args[]){A.method(5);}} Compile time error as final method can't be overloaded None of these Method 2 Method 1 TRUE ANSWER : ? YOUR ANSWER : ?