SCJP Practice questions – 1

Share this Article :


Question 32)

What will happen when you attempt to compile and run this program
public class Outer{
public String name = “Outer”;
public static void main(String argv[]){
Inner i = new Inner();
i.showName();
}//End of main

private class Inner{
String name =new String(“Inner”);
void showName(){
System.out.println(name);
}
}//End of Inner class

}
1) Compile and run with output of “Outer”
2) Compile and run with output of “Inner”
3) Compile time error because Inner is declared as private
4) Compile time error because of the line creating the instance of Inner
Answer to Question to 32
________________________________________
Question 33)
What will happen when you attempt to compile and run this code
//Demonstration of event handling
import java.awt.event.*;
import java.awt.*;

public class MyWc extends Frame implements WindowListener{
public static void main(String argv[]){
MyWc mwc = new MyWc();
}
public void windowClosing(WindowEvent we){
System.exit(0);
}//End of windowClosing

public void MyWc(){
setSize(300,300);
setVisible(true);
}
}//End of class
1) Error at compile time
2) Visible Frame created that that can be closed
3) Compilation but no output at run time
4) Error at compile time because of comment before import statements
Answer to Question 33)
________________________________________
Question 34)
Which option most fully describes will happen when you attempt to compile and run the following code
public class MyAr{
public static void main(String argv[]) {
MyAr m = new MyAr();
m.amethod();
}
public void amethod(){
static int i;
System.out.println(i);
}
}
1) Compilation and output of the value 0
2) Compile time error because i has not been initialized
3) Compilation and output of null
4) Compile time error
Answer to Question 34)
________________________________________
Question 35)
Which of the following will compile correctly
1) short myshort = 99S;
2) String name = ‘Excellent tutorial Mr Green’;
3) char c = 17c;
4)int z = 015;
Answer to Question 35)
________________________________________
Question 36)
Which of the following are Java key words
1)double
2)Switch
3)then
4)instanceof
Answer to Question 36)
________________________________________

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Written by bhaskar

{bhaskar has written 11 posts on ITTreats.com . See all posts by }


Leave a Reply