File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dan's exam on inner classes

 
geeta rai
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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?
Thanks
 
Anand Ko
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don Wood
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
Dorothy Finkel-Laverty
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1865
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic