Q 1 : What will be the output?
[code lang=”java”]
public class Test1{
public static void main(String args[]){
System.out.println(method());
}
public static int method(){
try{
return 1;
}
catch(Exception e){
return 2;
}
finally{
return 3;
}
}
}
[/code]
Choose the one below:
- 1
- 2
- 3
- 0
Q 2 : What will be the output?
[code lang=”java”]
public class Test2{
public static void main(String args[]){
System.out.println(method());
}
public static int method(){
try{
throw new Exception();
return 1;
}
catch(Exception e){
return 2;
}
finally{
return 3;
}
}
}
[/code]
Choose the one below:
- 1
- 2
- 3
- 4
- Compiler error
Q 3 : What will be the output?
[code lang=”java”]
public class Test3{
public static void main(String args[]){
System.out.println(method());
}
public static int method(){
try{
throw new Exception();
}
catch(Exception e){
throw new Exception();
}
finally{
return 3;
}
}
}
[/code]
Choose the one below:
- 3
- 0
- Runtime Exception
- Compiler error
Q 4 : What will be the output?
[code lang=”java”]
public class Test4{
public static void main(String args[]){
System.out.println(method());
}
public static int method(){
return;
}
}
[/code]
Choose the one below:
- null
- 0
- Runtime exception
- Compiler error
Q 5 : What will be the output?
[code lang=”java”]
import java.io.IOException;
public class Test5{
public static void main(String args[]){
try{
throw new IOException();
}
catch(Exception e){
System.out.println("Excepion");
}
catch(IOException e){
System.out.println("IOExcepion");
}
}
}
[/code]
Choose the one below:
- Exception
- IOException
- Exception IOException
- Compilers error
Q 6 : What will be the output?
[code lang=”java”]
public class Test6{
public static void main(String args[]) throws Exception{
try{
throw new Exception();
}
finally{
System.out.println("No Error");
}
}
}
[/code]
Choose the one below:
- No Error followed by java.lang.Exception
- java.lang.Exception followed by No Error
- No Error
- Compiler Error
Q 7 : What will be the output?
[code lang=”java”]
public class Test7{
public static void main(String args[]) throws Exception{
Test7 t = new Test7();
t.method();
System.out.println("Print");
}
public void method()throws Exception{
throw new Exception();
}
}
[/code]
Choose the one below:
- Exception thrown at runtime
- no output
- Compiler Error
Q 8 : What will be the output?
[code lang=”java”]
public class Test8{
public static void main(String args[]) throws Exception{
Test8 t = new Test8();
t.method();
System.out.println("Print");
}
public void method(){
try{
throw new Exception();
}catch(Exception e){}
}
}
[/code]
Choose the one below:
- Exception thrown at runtime
- no output
- Compiler Error
Q 9 : What will be the output?
[code lang=”java”]
public class Test9 extends A{
public static void main(String args[]) throws Exception{
Test9 t = new Test9();
}
}
class A{
A() throws Exception{
System.out.println("A Class");
}
}
[/code]
Choose the one below:
- A Class
- Runtimxception
- no output
- Compiler Error
Q 10 : What will be the output?
[code lang=”java”]
public class Test10 extends A{
Test10()throws Exception{
System.out.println("Test10 Class");
}
public static void main(String args[]) throws Exception{
Test10 t = new Test10();
}
}
class A{
A() throws Exception{
System.out.println("A Class");
}
}
[/code]
Choose the one below:
- A Class Test10 Class
- Runtimxception
- no output
- Compiler Error
Q 11 : What will be the output?
[code lang=”java”]
public class Test11 extends A{
Test11()throws Exception{
System.out.println("Test10 Class");
}
Test11(int i){}
public static void main(String args[]) throws Exception{
Test11 t = new Test11();
}
}
class A{
A() throws Exception{
System.out.println("A Class");
}
}
[/code]
Choose the one below:
- A Class Test10 Class
- Runtimxception
- no output
- Compiler Error
Q 12 : What will be the output?
[code lang=”java”]
import java.io.IOException;
public class Test12 extends A{
public void method() throws Exception{
System.out.println("Subclass");
}
public static void main(String args[]) throws Exception{
A a = new A();
a.method();
a = new Test12();
a.method();
}
}
class A{
public void method() throws IOException{
System.out.println("Superclass");
}
}
[/code]
Choose the one below:
- Subclass Superclass
- Runtimxception
- Superclass Superclass
- Compiler Error
Q 13 : What are the legal arguments types for switch?
- int
- byte
- char
- All the above.
Q 14 : Which of the following are valif if constructs?
- if(2>3){}
- if(false){}
- if(false){}
- if(true)
Q 15 : What will be the output?
[code lang=”java”]
public class Test15{
public static void main(String args[]) throws Exception{
for (int i = 0;i < 3;i++){
for (int j = 0;j < 3;j++){
System.out.print(i);
System.out.print(j+",");
break;
}
}
}
}
[/code]
Choose the one below:
- 00,
- 00,10,20,
- 000102
- None of the above
Q 16 : What will be the output?
[code lang=”java”]
public class Test16 extends A{
Test16(){
System.out.println("Sub");
}
public static void main(String args[]) {
Test16 t = new test16();
}
}
class A{
A(int i){
System.out.println("Super");
}
}
[/code]
Choose the one below:
- Super Sub
- Super
- Sub
- Compiler Error
Q 17 : What will be the output?
[code lang=”java”]
public class Test17 extends A{
Test17(int i){
System.out.println(i);
super(2);
}
public static void main(String args[]) {
Test17 t = new Test17(5);
}
}
class A{
A(int i){
System.out.println(i);
}
}
[/code]
Choose the one below:
- 5 2
- 2 5
- 5 5
- Compiler error
Q 18 : What will be the output?
[code lang=”java”]
public class Test18 {
Test18(){
this(7);
}
Test18(int i){
this(1.0);
Test18(i);
}
Test18(float f){
System.out.println(f * 2);
}
Test18(double d){
System.out.println(d * 3);
}
void Test18(int i){
System.out.println(i);
}
public static void main(String args[]) {
Test18 t = new Test18();
}
}
[/code]
Choose the one below:
- 3.0 7
- 2.0 7
- 7 3.0
- Compiler Error
Q 19 : What will be the output?
[code lang=”java”]
public class Test19 {
float f;
Test19(){
this(f);
f = 3;
}
Test19(float f){
System.out.println(f);
}
public static void main(String args[]) {
Test19 t = new Test19();
}
}
[/code]
Choose the one below:
- 0.0
- 0
- 3
- Compiler error
Q 20 : What will be the output?
[code lang=”java”]
public class Test20 extends A{
Test20(){
this("Hi");
}
Test20(String str){
System.out.println(str);
}
public static void main(String args[]) {
Test20 t = new Test20();
}
}
class A{
A(){
System.out.println("Super");
}
}
[/code]
Choose the one below:
- Super Hi
- Hi Super
- Super
- Compiler Error
Q 21 : What will be the output?
[code lang=”java”]
public class Test21{
public static void main(String args[]) {
Test21 t;
t.method();
}
public static void method(){
System.out.println("NullPointerException");
}
}
[/code]
Choose the one below:
- Nothing is printed.
- RuntimeException
- NullPointerException
- Compiler Error
Q 22 : What will be the output?
[code lang=”java”]
public class Test22{
public static void main(String args[]) {
Test22 t = null;
t.method();
}
public static void method(){
System.out.println("NullPointerException");
}
}
[/code]
Choose the one below:
- Nothing is printed.
- RuntimeException
- NullPointerException
- Compiler Error
Q 23 : Which of the following modifiers are allowed in constructor?
- private
- default
- public
- static
Q 24 : Which of the following modifiers are allowed for top-level classes?
- private
- static
- public
- strictfp
Q 25 : which one of the keyword cannot be used with instance variables?
- transient
- volatile
- synchronized
- abstract
Answers
Q 1 : 3 is correct. 3.
Q 2 : 4 is correct. Compiler Error.
Q 3 : 4 is correct. Compiler Error.
Q 4 : 4 is correct. Compiler Error.
Q 5 : 4 is correct. Compiler Error.
Q 6 : 1 is correct. No Error followed by java.lang.Exception
Q 7 : 2 is correct. Exception thrown at runtime.
Q 8 : 1 is correct. Print.
Q 9 : 4 is correct. Compiler Error.
Q 10 : 1 is correct. A Class Test10 Class.
Q 11 : 4 is correct. Compiler Error.
Q 12 : 4 is correct. Compiler Error.
Q 13 : 4 is correct. All the above.
Q 14 : 1 is correct. if(2>3){}
2 is correct. if(false){}
4 is correct. if(true){}
Q 15 : 2 is correct. 00,10,20,
Q 16 : 4 is correct. Compiler Error.
Q 17 : 4 is correct. Compiler Error.
Q 18 : 1 is correct. 3.0 7
Q 19 : 4 is correct. Compiler Error.
Q 20 : 1 is correct. Super Hi.
Q 21 : 4 is correct. Compiler Error.
Q 22 : 3 is correct. NullPointerException.
Q 23 : 1 is correct. private.
3 is correct. public.
Q 24 : 4 is correct. strictfp.
3 is correct. public.
Q 25 : 3 is correct. synchronized.
4 is correct. abstrct.
Leave a Reply