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 None of these Compilation Error two one one one Exception 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();}} Wild Animal Animal Wild Runtime Exception Compilation Error TRUE ANSWER : ? YOUR ANSWER : ?
The implicit return type of a constructor is void A class object in which it is defined. There is no return type. None of these 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 ? A a = new A(String s); A a = new B(5); All of these A a = new B(); None of these TRUE ANSWER : ? YOUR ANSWER : ?
What will be the return type of a method that not returns any value? void double None of these int TRUE ANSWER : ? YOUR ANSWER : ?
The variables declared in a class for the use of all methods of the class are called reference variables objects instance variables None of these 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 ) ; } } None of these 2.0 0 Compile time error TRUE ANSWER : ? YOUR ANSWER : ?
The main method should be static for the reason None of these It can be accessed easily by the class loader. 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 : ?
The finalize() method is called just prior to An object or variable goes out of scope. An object, variable or method goes out of scope. Before garbage collection. None of these A variable goes out of scope. 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.} Compile fail due to error on line no 9 Compile fail due to error on line no 8 Compile fail due to error on line no 2 15 None of these TRUE ANSWER : ? YOUR ANSWER : ?