Which of the modifier can't be used for constructors? static private public protected TRUE ANSWER : ? YOUR ANSWER : ?
What will be the return type of a method that not returns any value? None of these void int double TRUE ANSWER : ? YOUR ANSWER : ?
public class MyClass{ }For the above class(MyClass) what is the correct way of declaring constructor? public MyClass(void){} 1 and 3 public MyClass(){} MyClass(void) {} MyClass(){} 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 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 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 fails due to an error on line 1 One Compilation fails due to an error on line 2 Compilation succeed but no output. TRUE ANSWER : ? YOUR ANSWER : ?
The variables declared in a class for the use of all methods of the class are called objects reference variables instance variables None of these TRUE ANSWER : ? YOUR ANSWER : ?
Which of the following options is the best for generating random integer 0 or 1? (int)(Math.random() + 0.5) (int)Math.random() (int)Math.random() + 1 (int)(Math.random() + 0.2) 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.} 15 Compile fail due to error on line no 2 Compile fail due to error on line no 9 Compile fail due to error on line no 8 None of these TRUE ANSWER : ? YOUR ANSWER : ?
What is the expected output?public class Profile { private Profile(int w) { // line 1 System.out.print(w); } public static Profile() { // line 5 System.out.print (10); } public static void main(String args[]) { Profile obj = new Profile(50); }} Won't compile because of line (5), constructor can't be static 50 10 50 Won't compile because of line (1), constructor can't be private 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);}} 10 50 50 Won't compile because of line (1); constructor can't be private Won't compile because of line (5); constructor can't be final TRUE ANSWER : ? YOUR ANSWER : ?