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 1, constructor Tester must be marked public like its class At line 4 At line 3, compilation error, ambiguity problem, compiler can't determine whether a constructor At line 2, constructor call 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 ) ; } } 0 Compile time error 2.0 None of these TRUE ANSWER : ? YOUR ANSWER : ?
What is the expected output?public class Profile {private Profile(int w) { // line 1System.out.print(w);}public final Profile() { // line 5System.out.print(10);}public static void main(String args[]) {Profile obj = new Profile(50);}} Won't compile because of line (1); constructor can't be private 10 50 Won't compile because of line (5); constructor can't be final 50 TRUE ANSWER : ? YOUR ANSWER : ?
What is the output for the below code?public class Test{ public static void printValue(int i, int j, int k){ System.out.println("int"); } public static void printValue(byte...b){ System.out.println("long"); } public static void main(String... args){ byte b = 9; printValue(b,b,b); }} int Compilation clean but throws RuntimeException long Compilation fails None of these 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(); }} None of these two one one one one two Compilation Error one Exception 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)); } } does not compile None of these The sum of x and y is 9 The sum of x and y is 45 TRUE ANSWER : ? YOUR ANSWER : ?
The implicit return type of a constructor is There is no return type. None of these A class object in which it is defined. void TRUE ANSWER : ? YOUR ANSWER : ?
The variables declared in a class for the use of all methods of the class are called reference variables instance variables None of these objects TRUE ANSWER : ? YOUR ANSWER : ?
Which of the following options is the best for generating random integer 0 or 1? (int)Math.random() (int)Math.random() + 1 (int)(Math.random() + 0.2) (int)(Math.random() + 0.5) TRUE ANSWER : ? YOUR ANSWER : ?
Which of the modifier can't be used for constructors? private public static protected TRUE ANSWER : ? YOUR ANSWER : ?