JAVA Constructors and Methods Which of the following options is the best for generating random integer 0 or 1? (int)(Math.random() + 0.5) (int)Math.random() + 1 (int)Math.random() (int)(Math.random() + 0.2) (int)(Math.random() + 0.5) (int)Math.random() + 1 (int)Math.random() (int)(Math.random() + 0.2) ANSWER DOWNLOAD EXAMIANS APP
JAVA Constructors and Methods 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 0 None of these Compile time error 2.0 0 None of these Compile time error ANSWER DOWNLOAD EXAMIANS APP
JAVA Constructors and Methods 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 2 Compilation fails due to an error on line 1 One Compilation succeed but no output. Compilation fails due to an error on line 2 Compilation fails due to an error on line 1 One ANSWER DOWNLOAD EXAMIANS APP
JAVA Constructors and Methods 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 2, constructor call At line 3, compilation error, ambiguity problem, compiler can't determine whether a constructor At line 1, constructor Tester must be marked public like its class At line 4 At line 2, constructor call At line 3, compilation error, ambiguity problem, compiler can't determine whether a constructor At line 1, constructor Tester must be marked public like its class ANSWER DOWNLOAD EXAMIANS APP
JAVA Constructors and Methods 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 Exception Compilation Error two one one None of these one one two one Exception Compilation Error two one one None of these one one two ANSWER DOWNLOAD EXAMIANS APP
JAVA Constructors and Methods The implicit return type of a constructor is void None of these There is no return type. A class object in which it is defined. void None of these There is no return type. A class object in which it is defined. ANSWER DOWNLOAD EXAMIANS APP