File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan's exam on inner classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Storm Applied this week in the Other Open Source APIs forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dan Watch "Dan New topic

Dan's exam on inner classes

geeta rai
Ranch Hand

Joined: Sep 18, 2003
Posts: 48
Questions 13 and 14 from inner classes
abstract class
A { // 1
abstract final void m1(); // 2
abstract final class B {} // 3
class C extends B {} // 4
The answer is line 1. I think the answer should be 2 and 3
abstract class A
{ // 1
abstract synchronized void m1(); // 2
abstract synchronized class B {} // 3
synchronized class C extends B {} // 4
The answer is line 1 again but i think the compiler would raise errors on lines 3 and 4
Can someone put some light?
Anand Ko
Ranch Hand

Joined: Dec 03, 2003
Posts: 79
Ever I agree with her.
Q 13) Line 2 &3 give error. Also on line 4 since it is extending final class.
Q 14) line 2 & 4 gives error. Also line 3, since we can't have combination of abstract & synchronized.

Anand<br />SCJP 1.4, SCWCD 1.4, SCEA 5.0(1/3)
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Perhaps a good answer is found by actually trying to compile the examples, and seeing what your compiler has to say. Mine complains about 2, 3, and 4 (not in that order) on both examples, and about line 1 in neither.
I don't see anything wrong with line 1 in either example.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Don Wood
Ranch Hand

Joined: Dec 05, 2003
Posts: 65
I looked at Dan's questions on nested classes and the question that is asked in both cases is:
Which line does not result in a compile-time error?

So the correct answer to each of these questions is line 1.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Dirk Schreckmann:
[QB]Perhaps a good answer is found by actually trying to compile the examples, and seeing what your compiler has to say.[QB]

I agree with Dirk Schreckmann... Since SCJP exam developers want the candidates to think like a compiler, we should try to compile any codes that we doubt and find out the result...
So to pass the exam, try to be a compiler....

Co-author of SCMAD Exam Guide, Author of JMADPlus
Dorothy Finkel-Laverty
Ranch Hand

Joined: Nov 24, 2001
Posts: 51
So let's talk about WHY the other lines would generate compiler errors.
"abstract" says that the method MUST be overridden.
"final" says that the method CANNOT be overridden.
Since they are in conflict, the compiler will generate error messages. There were lots of questions like this on the exam when I took it a few years back.
That explains lines 2 & 3 -
Line 4 cannot compile because there is no class B, since the earlier lines did not compile. Also, class B is supposed to be final, so you can't extend it.
[ December 16, 2003: Message edited by: Dorothy Finkel-Laverty ]
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
As Don pointed out earlier, the question asks the following.
Which line does not result in a compile-time error?

I will add the following sentence to each answer explanation.
Please note that this question asks which line
does NOT result in a compile time error.

Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="" target="_blank" rel="nofollow">Try my mock exam.</a>
I agree. Here's the link:
subject: Dan's exam on inner classes