This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes difference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "difference" Watch "difference" New topic
Author

difference

chinnanu chinna
Greenhorn

Joined: May 28, 2007
Posts: 10
what is differnce between follwing:

goFast() { }

and

goFast();



thank you
Vidhya Ramaswamy
Ranch Hand

Joined: Oct 10, 2007
Posts: 65
void goFast() { } is a complete method in itself, it is indicated by the curly braces { }, although there is no code inside(it can be added later).

Whereas, void goFast(); cannot be used just as is. The semi-colon at the end instead of curly braces means this method does not have/cannot have code. When used in a class, it MUST be marked abstract such as


Java states that the class which has even one single abstract method must be itself declared abstract, else it won't compile. In this case, the first concrete subclass of this class is required to write the code for this method(Again, even it is void goFast() { }, it is legal, although it doesn't make sense to have nothing in the method)

void goFast() { } can be used with interface declaration, where the abstract keyword is optional (all methods in an interface are abstract and public by default). Again, the concrete class implementing this interface needs to compulsarily write the method body.
eg.


Hope that helps.
Vidhya
Vidhya Ramaswamy
Ranch Hand

Joined: Oct 10, 2007
Posts: 65
Sorry, the above post has some correction in one line ( goFast(); to be used instead of goFast() {}).

Here is the correction:

void goFast(); can be used with interface declaration, where the abstract keyword is optional (all methods in an interface are abstract and public by default). Again, the concrete class implementing this interface needs to compulsarily write the method body.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference