The main method should be static for the reason It can be accessed easily by the class loader. 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. TRUE ANSWER : ? YOUR ANSWER : ?
class A{ A(String s){} A(){}}1. class B extends A{2. B(){}3. B(String s){4. super(s);5. }6. void test(){7. // insert code here8. }9. }Which of the below code can be insert at line 7 to make clean compilation ? None of these A a = new B(); A a = new B(5); A a = new A(String s); All of these TRUE ANSWER : ? YOUR ANSWER : ?
Which of the modifier can't be used for constructors? protected static private public TRUE ANSWER : ? YOUR ANSWER : ?
public class MyClass{ }For the above class(MyClass) what is the correct way of declaring constructor? MyClass(){} public MyClass(){} 1 and 3 public MyClass(void){} MyClass(void) {} TRUE ANSWER : ? YOUR ANSWER : ?
The variables declared in a class for the use of all methods of the class are called reference variables None of these instance variables objects TRUE ANSWER : ? YOUR ANSWER : ?
What is the output of the program?class Test{ public int display(int x, int y){ return ("The sum of x and y is " + x + y); } public static void main(String args[]){ Test test = new Test(); System.out.println(test.display(4,5)); } } The sum of x and y is 45 does not compile None of these The sum of x and y is 9 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);}} Method 1 None of these Compile time error as final method can't be overloaded Method 2 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(); }} one one two Compilation Error None of these one Exception two one one TRUE ANSWER : ? YOUR ANSWER : ?
The following code contains one compilation error, find it?public class Test {Test() { } // line 1static void Test() { this(); } // line 2 public static void main(String[] args) { // line 3Test(); // line 4}} At line 4 At line 1, constructor Tester must be marked public like its class At line 3, compilation error, ambiguity problem, compiler can't determine whether a constructor At line 2, constructor call TRUE ANSWER : ? YOUR ANSWER : ?