aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can you implement an abstract method with an empty implementation? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Can you implement an abstract method with an empty implementation?" Watch "Can you implement an abstract method with an empty implementation?" New topic
Author

Can you implement an abstract method with an empty implementation?

Yin Stadfield
Ranch Hand

Joined: Oct 13, 2012
Posts: 34

Hi, is it possible?

You extend an interface/abstract, so you need to have to implement its methods. But what if you just changed the semicolon to curly braces in the subclass, and there's nothing in between the curly braces. Is it possible/legal?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18133
    
  39

Yin Stadfield wrote:Hi, is it possible?

You extend an interface/abstract, so you need to have to implement its methods. But what if you just changed the semicolon to curly braces in the subclass, and there's nothing in between the curly braces. Is it possible/legal?



And what happened what you tried it? Also, don't forget to try it for methods that are not declared as void too.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Yin Stadfield
Ranch Hand

Joined: Oct 13, 2012
Posts: 34

Henry Wong wrote:
Yin Stadfield wrote:Hi, is it possible?

You extend an interface/abstract, so you need to have to implement its methods. But what if you just changed the semicolon to curly braces in the subclass, and there's nothing in between the curly braces. Is it possible/legal?



And what happened what you tried it? Also, don't forget to try it for methods that are not declared as void too.

Henry


I just tried it now. Works fine for method that are declared as void and just as long as the implementation is marked as public. And empty method implementation won't work for methods with a return type, since the compiler requires a return statement. Thanks, Henry!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can you implement an abstract method with an empty implementation?
 
Similar Threads
can't be resolved to a type error
Reg ; after a method
Why a class declared as Abstract, cannot have any abstract method declaration?
Some Basic Questions
Unreachable catch block for ClassNotFoundException