Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Dan's exam on inner classes

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic