1. What will be the output of the following Program?
class A {}
class B extends A
{
public void show()
{
System.out.println("Bye");
}
public static void main(String [] rk)
{
A a1 = new B();
a1.show();
}
}
A. Bye B. Compilation Error
C. Runtime Error D. None of These
2. What will be the output of the following Program?
class A
{
private A(){}
}
class B extends A
{
B()
{
System.out.println("Bye");
}
public static void main(String [] rk)
{
A a1 = new B();
}
}
A. Bye B. Compilation Error
C. Runtime Error D. None of These
3. What will be the output of the following Program?
class A
{
public void show()
{
System.out.println("Hi");
}
}
class B extends A
{
public void show()
{
System.out.println("Bye");
}
public static void main(String [] rk)
{
A a1 = new B();
a1.show();
}
}
A. Bye B. Compilation Error
C. Runtime Error D. Hi
4. What will be the output of the following Program?
class A
{
A(int x) { this("Hi");
System.out.print("L");
}
private A(String x) {
System.out.print("P");
}
}
class B extends A
{
private B(){ super(1);
System.out.print("U");
}
public static void main(String [] rk)
{
B b1 = new B();
}
}
A. PLU B. LPU
C. ULP D. Compilation Error
5. What will be the output of the following code snippet?
class Test{
public void display(int x, double y){
System.out.println(x+y);
}
public double display(int a, double b){
return (a*b);
}
public static void main(String args[]){
Test t = new Test();
t.display(4, 5.0);
}
}
A. 9 B. 36
C. Compilation Error D. None of These
6. What will be the output of the following code snippet?
class A
{
public static void demo()
{
System.out.println("Hi");
}
}
class B extends A
{
public static void demo()
{
System.out.println("Hello");
}
public static void main(String [] rk)
{
A a1 = new B();
a1.demo();
}
}
A. Hi B. Hello
C. Compilation Error D. Runtime Error
7. What will be the output of the following code snippet?
class A
{
public void demo()
{
System.out.println("Hi");
}
}
class B extends A
{
public void demo()
{
System.out.println("Hello");
}
public static void main(String [] rk)
{
A a1 = new B();
a1.demo();
}
}
A. Hi B. Hello
C. Compilation Error D. Runtime Error
8. What will be the output of the folowing code snippet?
public class Test{
public static void main(String [] rk){
int i;
for(i = 1; i < 6; i++)
{
if(i > 3) continue;
}
System.out.println(i);
}
}
A. 4 B. 5 C. 6 D. None of
These
9. What will be the output of the folowing code snippet?
public class Test{
public static void main(String [] rk){
int i;
for(i = 1; i < 6; i++)
{
if(i > 3) break;
}
System.out.println(i);
}
}
A. 4 B. 5 C. 6 D. None of
These
10. What will be the output?
class Demo{
public static void main(String[] rk){
int [] a = new int[0];
System.out.print(a.length);
}
}
A. 0 B. 10 C. Compilation Error D. None of These
11. What will be the output?
class Demo{
public static void main(String[] rk){
int a [10];
System.out.print(a.length);
}
}
A. 0 B. 10 C. Compilation Error D. None of These
12. What will be the output?
public class StringDemo{
public static void main(String [] rk){
String s1 = new String("Hi");
String s2 = new String("Bye");
System.out.println(s1 = s2);
}
}
A. Hi B. Bye
C. Compilation Error D. None
13. What will be the output?
public class StringDemo{
public static void main(String [] rk){
String s1 = new String("Hi");
String s2 = new String("Bye");
System.out.println(s1 == s2);
}
}
A. true B. false
C. Compilation Error D. None
14. What will be the output?
class TestString{
public static void main(String args[]){
String s1 = new String("Hello");
String s2 = new String(s1);
System.out.println(s1 == s2);
}
}
A. true B. false
C. Compilation Error D. None
15. What will be the output?
class TestString{
public static void main(String args[]){
String s1 = new String("Hello");
String s2 = new String(s1);
System.out.println(s1.equals(s2));
}
}
A. true B. false
C. Compilation Error D. None
16. What will be the output?
StringBuilder b = new StringBuilder('A');
System.out.println(b.capacity() + ""+ b.length());
A.810 B. 811 C. 171 D. 650
17. What will be the output?
ArrayList a = new ArrayList();
a.add("A"); a.add("B");
a.set(1, "X"); a.add(2, "C");
System.out.println(a);
A. [A, X, B, C] B.[A, X, B]
C. [A, X, C] D. Runtime Error
18. Which of the following is an invalid array declaration?
A. int ... arr;
B. char ch [] = {A, B, C, D, E};
C. boolean [] b = {false, true, true};
D. Object ob [] = new Object[10];
19. What will be the output of the following statement?
System.out.println( 3>4 || 4>3 ? false : true);
A. true B. false
C. falsetruefalse D. Compilation Error
20. The following class is saved in a file named as
Hello.java. Which of the following is TRUE about it?
public class A{}
A. It can be compiled using command javac A.java
B. It will be compiled using command javac A.java
C. It must be saved in a file named as A.java, otherwise it
will not compile.
D. None of These
21. Which of the following is CORRECT char variable
declaration?
A. char c = (int)65.1;
B. char c = a;
C. char c = '11';
D. None of These;
22. What will be the output of the following code snippet?
if(!true) System.out.print("Hi ");
if(true) System.out.print("Hello ");
else("Bye");
A. Hi Bye B. Hello C. Bye D. Compilation Error
23. We can use these features of an abstract class even
without inheriting it.
A. all the public static and non static members
B. all the public static members
C. all the public non static members
D. none of the above
24. Singleton Design pattern is used ___.
A. To ensure that the inheritance of the class is prevented.
B. To ensure that only one instance of the class can be
created.
C. To ensure that all the abstract methods are implemented
by the subclass.
D. Both A and B
25. Can an abstract parent class have non-abstract children?
A. No--an abstract parent must have only abstract children.
B. No--an abstract parent must have no children at all.
C. Yes--all children of an abstract parent must be non-
abstract.
D. Yes--an abstract parent can have both abstract and non-
abstract children.
26. Which of the following is FALSE about final keyword in
Java?
A. It is used to prevent the inheritance of a class.
B. It is used to declare the constant in Java.
C. Local variables can not be declared final.
D. Abstract class can not be declared final.
27. Which of the following is FALSE about Abstract class?
A. Abstract class can not inherit another abstract class.
B. Abstract class can have constructors.
C. Abstract class can not be declared private.
D. Abstract class can contain non-abstract methods.
28. What will be the output of the following code?
class Test
{
int x=10;
Test(int a)
{
System.out.print(x);
x=a;
}
public static void main(String [] arg)
{
new Test(5);
}
}
A. 0 B. 5 C. 10 D. Compilation Error
29. What will be the output of the following code snippet?
ArrayList al = new ArrayList();
al.add("A"); al.add("B"); al.add("C");
ArrayList al2 = new ArrayList();
al2.add("Hi");
al.add(2, al2)
System.out.println(al);
A. [A, B, Hi, C]]
B. [A, B, [Hi], C]
C. [A, [Hi], B, C]
D. Compilation Error
30. Which of the following is INCORRECT header for the main
method in java?
A. public static void main(String [] arg)
B. static public void main(String arg [])
C. public static void main(String...arg)
D. None of These
class A {}
class B extends A
{
public void show()
{
System.out.println("Bye");
}
public static void main(String [] rk)
{
A a1 = new B();
a1.show();
}
}
A. Bye B. Compilation Error
C. Runtime Error D. None of These
2. What will be the output of the following Program?
class A
{
private A(){}
}
class B extends A
{
B()
{
System.out.println("Bye");
}
public static void main(String [] rk)
{
A a1 = new B();
}
}
A. Bye B. Compilation Error
C. Runtime Error D. None of These
3. What will be the output of the following Program?
class A
{
public void show()
{
System.out.println("Hi");
}
}
class B extends A
{
public void show()
{
System.out.println("Bye");
}
public static void main(String [] rk)
{
A a1 = new B();
a1.show();
}
}
A. Bye B. Compilation Error
C. Runtime Error D. Hi
4. What will be the output of the following Program?
class A
{
A(int x) { this("Hi");
System.out.print("L");
}
private A(String x) {
System.out.print("P");
}
}
class B extends A
{
private B(){ super(1);
System.out.print("U");
}
public static void main(String [] rk)
{
B b1 = new B();
}
}
A. PLU B. LPU
C. ULP D. Compilation Error
5. What will be the output of the following code snippet?
class Test{
public void display(int x, double y){
System.out.println(x+y);
}
public double display(int a, double b){
return (a*b);
}
public static void main(String args[]){
Test t = new Test();
t.display(4, 5.0);
}
}
A. 9 B. 36
C. Compilation Error D. None of These
6. What will be the output of the following code snippet?
class A
{
public static void demo()
{
System.out.println("Hi");
}
}
class B extends A
{
public static void demo()
{
System.out.println("Hello");
}
public static void main(String [] rk)
{
A a1 = new B();
a1.demo();
}
}
A. Hi B. Hello
C. Compilation Error D. Runtime Error
7. What will be the output of the following code snippet?
class A
{
public void demo()
{
System.out.println("Hi");
}
}
class B extends A
{
public void demo()
{
System.out.println("Hello");
}
public static void main(String [] rk)
{
A a1 = new B();
a1.demo();
}
}
A. Hi B. Hello
C. Compilation Error D. Runtime Error
8. What will be the output of the folowing code snippet?
public class Test{
public static void main(String [] rk){
int i;
for(i = 1; i < 6; i++)
{
if(i > 3) continue;
}
System.out.println(i);
}
}
A. 4 B. 5 C. 6 D. None of
These
9. What will be the output of the folowing code snippet?
public class Test{
public static void main(String [] rk){
int i;
for(i = 1; i < 6; i++)
{
if(i > 3) break;
}
System.out.println(i);
}
}
A. 4 B. 5 C. 6 D. None of
These
10. What will be the output?
class Demo{
public static void main(String[] rk){
int [] a = new int[0];
System.out.print(a.length);
}
}
A. 0 B. 10 C. Compilation Error D. None of These
11. What will be the output?
class Demo{
public static void main(String[] rk){
int a [10];
System.out.print(a.length);
}
}
A. 0 B. 10 C. Compilation Error D. None of These
12. What will be the output?
public class StringDemo{
public static void main(String [] rk){
String s1 = new String("Hi");
String s2 = new String("Bye");
System.out.println(s1 = s2);
}
}
A. Hi B. Bye
C. Compilation Error D. None
13. What will be the output?
public class StringDemo{
public static void main(String [] rk){
String s1 = new String("Hi");
String s2 = new String("Bye");
System.out.println(s1 == s2);
}
}
A. true B. false
C. Compilation Error D. None
14. What will be the output?
class TestString{
public static void main(String args[]){
String s1 = new String("Hello");
String s2 = new String(s1);
System.out.println(s1 == s2);
}
}
A. true B. false
C. Compilation Error D. None
15. What will be the output?
class TestString{
public static void main(String args[]){
String s1 = new String("Hello");
String s2 = new String(s1);
System.out.println(s1.equals(s2));
}
}
A. true B. false
C. Compilation Error D. None
16. What will be the output?
StringBuilder b = new StringBuilder('A');
System.out.println(b.capacity() + ""+ b.length());
A.810 B. 811 C. 171 D. 650
17. What will be the output?
ArrayList a = new ArrayList();
a.add("A"); a.add("B");
a.set(1, "X"); a.add(2, "C");
System.out.println(a);
A. [A, X, B, C] B.[A, X, B]
C. [A, X, C] D. Runtime Error
18. Which of the following is an invalid array declaration?
A. int ... arr;
B. char ch [] = {A, B, C, D, E};
C. boolean [] b = {false, true, true};
D. Object ob [] = new Object[10];
19. What will be the output of the following statement?
System.out.println( 3>4 || 4>3 ? false : true);
A. true B. false
C. falsetruefalse D. Compilation Error
20. The following class is saved in a file named as
Hello.java. Which of the following is TRUE about it?
public class A{}
A. It can be compiled using command javac A.java
B. It will be compiled using command javac A.java
C. It must be saved in a file named as A.java, otherwise it
will not compile.
D. None of These
21. Which of the following is CORRECT char variable
declaration?
A. char c = (int)65.1;
B. char c = a;
C. char c = '11';
D. None of These;
22. What will be the output of the following code snippet?
if(!true) System.out.print("Hi ");
if(true) System.out.print("Hello ");
else("Bye");
A. Hi Bye B. Hello C. Bye D. Compilation Error
23. We can use these features of an abstract class even
without inheriting it.
A. all the public static and non static members
B. all the public static members
C. all the public non static members
D. none of the above
24. Singleton Design pattern is used ___.
A. To ensure that the inheritance of the class is prevented.
B. To ensure that only one instance of the class can be
created.
C. To ensure that all the abstract methods are implemented
by the subclass.
D. Both A and B
25. Can an abstract parent class have non-abstract children?
A. No--an abstract parent must have only abstract children.
B. No--an abstract parent must have no children at all.
C. Yes--all children of an abstract parent must be non-
abstract.
D. Yes--an abstract parent can have both abstract and non-
abstract children.
26. Which of the following is FALSE about final keyword in
Java?
A. It is used to prevent the inheritance of a class.
B. It is used to declare the constant in Java.
C. Local variables can not be declared final.
D. Abstract class can not be declared final.
27. Which of the following is FALSE about Abstract class?
A. Abstract class can not inherit another abstract class.
B. Abstract class can have constructors.
C. Abstract class can not be declared private.
D. Abstract class can contain non-abstract methods.
28. What will be the output of the following code?
class Test
{
int x=10;
Test(int a)
{
System.out.print(x);
x=a;
}
public static void main(String [] arg)
{
new Test(5);
}
}
A. 0 B. 5 C. 10 D. Compilation Error
29. What will be the output of the following code snippet?
ArrayList al = new ArrayList();
al.add("A"); al.add("B"); al.add("C");
ArrayList al2 = new ArrayList();
al2.add("Hi");
al.add(2, al2)
System.out.println(al);
A. [A, B, Hi, C]]
B. [A, B, [Hi], C]
C. [A, [Hi], B, C]
D. Compilation Error
30. Which of the following is INCORRECT header for the main
method in java?
A. public static void main(String [] arg)
B. static public void main(String arg [])
C. public static void main(String...arg)
D. None of These
Good Post! Thank you so much for sharing the post, it was so good to read and useful to improve
ReplyDeleteJava Training in Electronic City