LogIn
I don't have account.
Q1.
What will be the output of following Java Code?
public class Main {
    public static void main(String[] args) {
        int myVar;
        System.out.print(myVar);
    }
}
1
1
compile time error
2
runtime error
3
0
4
garbage value
Q2.
What will be the output of following Java Code?
public class Main {
    public static void main(String[] args) {
        static int myVar;
        System.out.print(myVar);
    }
}
1
1
compile time error
2
runtime error
3
0
4
garbage value
Q3.
What will be the output of following Java Code?
public class Main {
    public static void main(String[] args) {
        char myVar;
        System.out.print(myVar);
    }
}
1
1
compile time error
2
runtime error
3
0
4
garbage value
Q4.
What will be the output of following Java Code?
public class Main {
    static char myVar;
    public static void main(String[] args) {
        System.out.print(myVar);
    }
}
1
1
compile time error
2
0
3
An empty space (because the default value of myVar is '\u0000')
4
null
Q5.
What will be the output of following Java Code?
public class Main {
    public static void main(String[] args) {
        static char myVar;
        System.out.print(myVar);
    }
}
1
1
compile time error
2
runtime error
3
0
4
garbage value
Q6.
What will be the output of following Java Code?
public class Main {
    char myVar;
    public static void main(String[] args) {
        Main obj = new Main();
        System.out.print(obj.myVar);
    }
}
1
1
compile time error
2
null
3
An empty space (because the default value of myVar is '\u0000')
4
''
5
0
Q7.
What will be the output of following Java Code?
public class Main {
     public static void main(String args[]){
        byte b;
        int i = 264;
        b = (byte) i;
        System.out.print(b); 
    }
}
1
1
8
2
127
3
264
4
None of the above
Q8.
What will be the output of following Java Code?
public class Main {
     public static void main(String args[]){
        byte b;
        int i = 264;
        double d = 215.59;
        b = (byte) i;
        System.out.print(b); 
        i = (int) d; 
        System.out.print(i); 
        b = (byte) d; 
        System.out.print(b); 
    }
}
1
1
8215-41
2
4215-41
3
264215264
4
None of the above
Q9.
What will be the output of the following Java program?
class A {
    void display() { System.out.println("Class A"); }
}
class B extends A {
    void display() { System.out.println("Class B"); }
}
public class Main {
    public static void main(String[] args) {
        A obj = new B();
        obj.display();
    }
}
1
1
Class A
2
Class B
3
Compilation Error
4
Runtime Error
Q10.
What is the output of the following Java program?
System.out.println('A' + 1);
1
1
B
2
A1
3
66
4
Compilation Error
Q11.
What will be the output of following Java Code?
public class Test {
    static {
        System.out.println("Static Block");
    }
    public static void main(String[] args) {
        System.out.println("Main Method");
    }
}
1
1
Main Method
2
Static Block
3
Static Block
Main Method
4
Main Method
Static Block
Q12.
What will be the output of following Java Code?
public class Test {
    public static void main(String[] args) {
        final int x = 10;
        x = 20;
        System.out.println(x);
    }
}
1
1
10
2
20
3
Compilation Error
4
Runtime Error
Q13.
What will be the output of following Java Code?
public class Test {
    public static void main(String[] args) {
        String a = "hello";
        String b = new String("hello");
        System.out.println(a == b);
    }
}
1
1
true
2
false
3
Compilation Error
4
Runtime Error
Q14.
What will be the output of following Java Code?
public class Test {
    public static void main(String[] args) {
        String a = "hello";
        String b = "hello";
        System.out.println(a == b);
    }
}
1
1
true
2
false
3
Compilation Error
4
Runtime Error
Q15.
What will be the output of following Java Code?
public class Test {
    public static void main(String[] args) {
        int x = 5;
        System.out.println(x++ + ++x);
    }
}
1
1
11
2
12
3
10
4
13
Q16.
What will be the output of following Java Code?
public class Test {
    void show(int a) {
        System.out.println("int");
    }
    void show(Integer a) {
        System.out.println("Integer");
    }
    public static void main(String[] args) {
        Test obj = new Test();
        obj.show(10);
    }
}
1
1
Integer
2
int
3
Compilation Error
4
Ambiguous method call
Q17.
What will be the output of following Java Code?
public class Test {
    void show(int a) {
        System.out.println("int");
    }
    void show(Integer a) {
        System.out.println("Integer");
    }
    public static void main(String[] args) {
        Test obj = new Test();
        Integer a = 10;
        obj.show(a);
    }
}
1
1
Integer
2
int
3
Compilation Error
4
Ambiguous method call
Q18.
What will be the output of following Java Code?
public class Test {
    void show(int a) {
        System.out.println("int");
    }
    void show(Integer a) {
        System.out.println("Integer");
    }
    public static void main(String[] args) {
        Test obj = new Test();
        Integer a = 10;
        obj.show((int)a);
    }
}
1
1
Integer
2
int
3
Compilation Error
4
Ambiguous method call
Q19.
What will be the output of following Java Code?
public class Test {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 4};
        System.out.println(nums[4]);
    }
}
1
1
4
2
0
3
Compilation Error
4
Runtime Exception
Q20.
What will be the output of following Java Code?
class Parent {
    Parent() {
        System.out.println("Parent Constructor");
    }
}
class Child extends Parent {
    Child() {
        System.out.println("Child Constructor");
    }
}
public class Test {
    public static void main(String[] args) {
        new Child();
    }
}
1
1
Parent Constructor
2
Child Constructor
3
Parent Constructor
Child Constructor
4
Child Constructor
Parent Constructor
Q21.
What will be the output of following Java Code?
public class Test {
    public static void main(String[] args) {
        String s = "abc";
        s.concat("def");
        System.out.println(s);
    }
}
1
1
abc
2
abcdef
3
def
4
Compilation Error
Q22.
What will be the output of following Java Code?
public class Test {
    public static void main(String[] args) {
        int a = 5;
        if (a > 5 && a++ < 10) {
            // nothing
        }
        System.out.println(a);
    }
}
1
1
5
2
6
3
Runtime Error
4
Compilation Error
Q23.
What will be the output of following Java Code?
public class Test {
    public static void main(String[] args) {
        String str = "null";
        int x= 5;
        if (str == null || x++ > 5) {
            System.out.println("True, x : "+x);
        }else{
            System.out.println("False,  x : "+x);
        }
    }
}
1
1
False, x : 6
2
True, x : 6
3
Runtime Error
4
Compilation Error
Q24.
What will be the output of following Java Code?
public class Test {
    public static void main(String[] args) {
        String str = "null";
        int x= 5;
        if (str == null || ++x > 5) {
            System.out.println("True, x : "+x);
        }else{
            System.out.println("False,  x : "+x);
        }
    }
}
1
1
False, x : 6
2
True, x : 6
3
Runtime Error
4
Compilation Error
Q25.
What will be the output of following Java Code?
public class Test {
    public static void main(String[] args) {
        String str = null;
        int x= 5;
        if (str == null || x++ > 5) {
            System.out.println("True, x : "+x);
        }else{
            System.out.println("False,  x : "+x);
        }
    }
}
1
1
False, x : 6
2
True, x : 6
3
Runtime Error
4
Compilation Error