The variables declared in a class for the use of all methods of the class are called instance variables None of these objects reference variables 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 Compilation fails due to an error on line 2 One Compilation succeed but no output. 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 : ?
What is the expected output?class Animal {Animal() {System.out.println("Animal");}}class Wild extends Animal{Wild() {System.out.println("Wild");super();}}public class Test {public static void main(String args[]) {Wild wild = new Wild();}} Runtime Exception Wild Animal Animal Wild Compilation Error TRUE ANSWER : ? YOUR ANSWER : ?
In which area of memory, the system stores parameters and local variables whenever a method is invoked? Stack Array Storage Area Heap TRUE ANSWER : ? YOUR ANSWER : ?
Which of the following statements regarding static methods are correct?1. Static methods are difficult to maintain, because you can not change their implementation.2. Static methods can be called using an object reference to an object of the class in which this method is defined.3. Static methods are always public, because they are defined at class-level.4. Static methods do not have direct access to non-static methods which are defined inside the same class. 3 and 4 1 and 2 1 and 3 2 and 4 TRUE ANSWER : ? YOUR ANSWER : ?
The main method should be static for the reason None of these It can be accessed by every method or variable without any hindrance. It can be executed without creating any instance of the class. It can be accessed easily by the class loader. 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 : ?
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(5); A a = new B(); All of these A a = new A(String s); TRUE ANSWER : ? YOUR ANSWER : ?