SCJP Practice questions – 1

Share this Article :


Question 41)
Given the following code
class Base{}

public class MyCast extends Base{
static boolean b1=false;
static int i = -1;
static double d = 10.1;

public static void main(String argv[]){
MyCast m = new MyCast();
Base b = new Base();
//Here
}
}
Which of the following, if inserted at the comment //Here will allow the code to compile and run without error

1) b=m;
2) m=b;
3) d =i;
4) b1 =i;
Answer to Question 41)
________________________________________
Question 42)
Which of the following statements about threading are true
1) You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements runnable
2) You can obtain a mutually exclusive lock on any object
3) A thread can obtain a mutually exclusive lock on a method declared with the keyword synchronized
4) Thread scheduling algorithms are platform dependent
Answer to Question 42)
________________________________________
Question 43)
Your chief Software designer has shown you a sketch of the new Computer parts system she is about to create. At the top of the hierarchy is a Class called Computer and under this are two child classes. One is called LinuxPC and one is called WindowsPC.
The main difference between the two is that one runs the Linux operating System and the other runs the Windows System (of course another difference is that one needs constant re-booting and the other runs reliably). Under the WindowsPC are two Sub classes one called Server and one Called Workstation. How might you appraise your designers work?

1) Give the goahead for further design using the current scheme
2) Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type
3) Ask for the option of WindowsPC to be removed as it will soon be obsolete
4) Change the hierarchy to remove the need for the superfluous Computer Class.

Answer to Question 43)
________________________________________
Question 44)
Which of the following statements are true
1) An inner class may be defined as static
2) There are NO circumstances where an inner class may be defined as private
3) An anonymous class may have only one constructor
4) An inner class may extend another class
Answer to Question 44)
________________________________________
Question 45)
What will happen when you attempt to compile and run the following code
int Output=10;
boolean b1 = false;
if((b1==true) && ((Output+=10)==20)){
System.out.println(“We are equal “+Output);
}else
{
System.out.println(“Not equal! “+Output);
}
1) Compile error, attempting to peform binary comparison on logical data type
2) Compilation and output of “We are equal 10″
3) Compilation and output of “Not equal! 20″
4) Compilation and output of “Not equal! 10″
Answer to Question 45)
________________________________________
Question 46)
Given the following variables which of the following lines will compile without error?
String s = “Hello”;
long l = 99;
double d = 1.11;
int i = 1;
int j = 0;
1) j= i <
2) j= i<
3) j=i<
4)j=i<
Answer to Question 46)
________________________________________
Question 47)
What will be output by the following line of code?
System.out.println(010|4);
1) 14
2) 0
3) 6
4) 12
Answer to Question 47)
________________________________________

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