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

"Complete the following so it compiles" - anything that compiles or the smallest bunch of code?

 
Piotr Kowalsky
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This type of question:
"Using the fragment below, complete the following code so it compiles" means to fill the gaps with any code that compiles or the smallest bunch of code that compiles?
(question taken from SCJP K&S 5, page 160)

I ask because the answer is different than I thought.

They fill it with:
AgedP(){}
----
-----
super();

and I did it with:
AgedP(){}
this();
-----
super();

which (I think) also compiles (but line "this();" isn't necessary).
 
W. Joe Smith
Ranch Hand
Posts: 710
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've copied the code I think you are meaning:


This won't complie, as it throws an "illegal start of type" method on this();.
 
Piotr Kowalsky
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see now. I didn't see "}" and thought it (this();) was inside this constructor:

but it wasn't. I was outside:


Now everything's clear. What a silly mistake!

Thank you!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic