Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Certification4Career SCJP Mock Exam Errors??

 
Lucy Das
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
The following questions are from Certification4Careers SCJP exams
I doubt some of the answers... your inputs will be greatly appreciated.Thanks in advance.
Exam#1
29. An inner class created inside a method can access
A. Any local variables of a method that contain an inner class.
B. Any instance variables of the enclosing class
C. Any final variables of the enclosing class or a method that contain an inner class.
D. None of the above
Ans is C. Me thinks its B,C
32. Please select invalid statement(s) for a thread
A. You can restart a dead thread
B. You can't call the methods of a dead thread
C. Both of the above
D. None of the above
The ans. is D. Isn't A invalid? I didn't think you could restart a dead thread.
38. Please select true statement for prefix operator(++x/--x).
A. The prefix operator(++x/--x) evaluates the value of the operand after increment/decrement operation.
B. The prefix operator(++x/--x) evaluates the value of the operand before increment/decrement operation.
C. Both A and B
D. None of the above
Ans is A. Am I missing something here? I thought it would be B.
65. 'null' is valid java type.
A. True
B. False
The answer is A. I guess the wording is unclear. -
How can null be a type?
-------------
SCJP Mock Exam 2
13. Consider following code:
public class OuterClass{
class InnerClass{
}
public void innerClassDemo(){
//Explicit instance of InnerClass
}
}
In above example, how can you explicitly create an instance of InnerClass?
A. InnerClass i=InnerClass();
B. InnerClass i=OuterClass.InnerClass();
C. InnerClass i=new OuterClass ().new InnerClass();
D. OuterClass.InnerClass i=new OuterClass.InnerClass();
Ans. is C,D; I picked C and that too I think it should be
OuterClass.InnerClass i = new OuterClass().new InnerClass();
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#29, #32 pass (for now)
#38 For prefix ++x(--x) the increment(decrement) is done first and then the result is used in the computation.
#65 null is a type, it's the type of the literal constant null.
#13 C, D both compile and run. In fact InnerClass i = new InnerClass(); does the same trick. Your version would also work.
Please do not post so many questions in one go, someone will post a complete exam soon.
-Barry
[ August 10, 2002: Message edited by: Barry Gaunt ]
 
zarina mohammad
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class OuterClass{
class InnerClass{
}
public void innerClassDemo(){
//Explicit instance of InnerClass
}
}
In above example, how can you explicitly create an instance of InnerClass?
A. InnerClass i=InnerClass();
B. InnerClass i=OuterClass.InnerClass();
C. InnerClass i=new OuterClass ().new InnerClass();
D. OuterClass.InnerClass i=new OuterClass.InnerClass();
Ans. is C,D; I picked C and that too I think it should be
OuterClass.InnerClass i = new OuterClass().new InnerClass();

The answers C,D are correct.
Both C and D are correct As long as you are not calling the OuterClass methods in innerClassDemo()
you can only call the InnerClass methods
 
zarina mohammad
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
29. An inner class created inside a method can access
A. Any local variables of a method that contain an inner class.
B. Any instance variables of the enclosing class
C. Any final variables of the enclosing class or a method that contain an inner class.
D. None of the above
Ans is C. Me thinks its B,C

yeah i think even B has to be included in the answer
 
David Poglitsch
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Specifically, the following compiles:

 
David Poglitsch
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
32. Please select invalid statement(s) for a thread
A. You can restart a dead thread
B. You can't call the methods of a dead thread
C. Both of the above
D. None of the above
The ans. is D. Isn't A invalid? I didn't think you could restart a dead thread.

Someone correct me if I'm wrong, but isn't the answer C.
You CANNOT restart a dead thread, BUT
you CAN call the methods of a dead thread.
So that would mean A & B are false.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, you are correct David. I am using an environment BlueJ in which you can create classes, instantate them, call their methods, and inspect them without having explicitly called a main method.
Makes life a little easier...
-Barry
[ August 11, 2002: Message edited by: Barry Gaunt ]
 
Lucy Das
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot everyone.
Barry - sorry for posting all the questions in one go.. I just compiled all the doubts I had relating to one specific Mock exam.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree the question about the null type is ambigous.
valid type? you cannot use null as a type in a Java program.
Yes I think 32 is C.
For 29 a nuisance
An inner class declared within a method cannot access any final local variable of the same method. The variable must be declared before the declaration of the inner class itself:
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jose,
regarding the null type, I love this piece of Java Language Specification Zen (4.1):
DRAFT
There is also a special null type, the type of the expression null, which has no
name. Because the null type has no name, it is impossible to declare a variable of
the null type or to cast to the null type. The null reference is the only possible
value of an expression of null type. The null reference can always be cast to any
reference type. In practice, the programmer can ignore the null type and just pretend
that null is merely a special literal that can be of any reference type.

-Barry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic