SCJP Practice questions – 1

Share this Article :


4) An interface that ensures that implementing classes cannot contain duplicates
________________________________________
Answer 21)
Objective 10.1)
2) The add method returns false if you attempt to add an element with a duplicate value
I find it a surprise that you do not get an exception.
________________________________________
Answer 22)
Objective 7.1)
1) The program exits via a call to exit(0);
2) The priority of another thread is increased
3) A call to the stop method of the Thread class

Java threads are somewhat platform dependent and you should be carefull when making assumptions about Thread priorities. On some platforms you may find that a Thread with higher priorities gets to “hog” the processor. You can read up on this in more detail at http://java.sun.com/docs/books/tutorial/essential/threads/priority.html
________________________________________
Answer 23)
Objective 4.1)
4) The class can only access final variables
________________________________________
Answer 24)
Objective 7.1)

1) To call from the currently running thread to allow another thread of the same or higher priority to run
Option 3 looks plausible but there is no guarantee that the thread that grabs the cpu time will be of a higher priority. It will depend on the threading algorithm of the Java Virtual Machine and the underlying operating system
________________________________________
Answer 25)
Objective 6.2)

4) Compilation and running with output 0 to 9
________________________________________
Answer 26)
Objective 2.1)
1) None of these options

Because of the lack of a break statement after the break 10; statement the actual output will be

“ten” followed by “twenty”
________________________________________
Answer 27)
Objective 3.1)
4) System.gc();
________________________________________
Answer 28)
Objective 4.4)
1) Compilation succeeds and at run time an output of 0 and false
The default value for a boolean declared at class level is false, and integer is 0;
________________________________________
Answer 29)
Objective 1.2)
1) Compile time error
You will get an error saying something like “Cant make a static reference to a non static variable”. Note that the main method is static.
________________________________________
Answer 30)
Objective 5.2)
3) Output of “Not equal”
Despite the actual character strings matching, using the == operator will simply compare memory location. Because the one string was created with the new operator it will be in a different location in memory to the other string.
________________________________________
Answer 31)
Objective 2.3)

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