Whizlabs offers SCJP 6.0 Exam Simulator with 420 questions as per the SCJP 6.0 certification exam. Following are couple of sample SCJP Questions.
Topic: Flow Control
SCJP Question statement: What is the result of compiling and running the given code?
class A
{
int b=10;
private A()
{
this.b=7;
}
int f()
{
return b;
}
}
class B extends A{ int b; }
class Test
{
public static void main(String[] args)
{
A a=new B();
System.out.println(a.f());
}
}
Choices:
Correct Answer: A
Explaination:
Choice A is the correct answer.
The code does not compile because the constructor of class A is declared as private. This creates a problem when the subclass constructor makes an implicit super() call to the parent class constructor at the time B is instantiated.
Since the code does not compile, all the other choices are incorrect. If the constructor of A had not been private, the output would have been 7.
Topic: Collections/Generics
SCJP Question statement: Which of these will compile and run? Select two choices.
Choices:
Correct Answer: B & C
Explaination:
Choices B and C are the correct answers.
The List interface is implemented by the LinkedList class. So List<Number> is the super type of LinkedList<Number>, which accepts only objects of type Number. LinkedList<Integer> declares a list that accepts only Integer objects. Assigning a LinkedList raw type to it gives warnings of unsafe operations, however, it does compile and run without errors.
Choice A is incorrect because generic parameters cannot be primitives.
Choice D is incorrect because the right hand side of the assignment uses the wrong syntax.
Choice E is incorrect because List<Number> is not a supertype of LinkedList<Integer>.
Reference:
http://java.sun.com/docs/books/tutorial/extra/generics/index.html
|
|
|
| What's Next? | |
![]() |
You can try out our 15 SCJP Questions Trial Test for FREE. Till now more than 19,000 participants have appeared in the trial exam . Try out the test and assess your rank compare to other test takers. This will help you to assess your strengths, weaknesses, speed and accuracy level in each Objective of SCJP 6 Certification Exam. If you are looking for more questions check out SCJP 1.6 Dumps. It has couple of interesting SCJP questions. |