GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Final methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Final methods" Watch "Final methods" New topic
Author

Final methods

Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Can an abstract class have final methods?
Kumaresh Vidhyasagar
Ranch Hand

Joined: Dec 05, 2008
Posts: 30
No you can't have
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Sure. Why wouldn't that be allowed?
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509


Even I was under the impression that they cant have. But look at the code above. it compiles fine.
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Paul Clapham wrote:Sure. Why wouldn't that be allowed?

Final methods cannot be overriden, but once they are inherited by the subclass, there is a possibility that they will be overridden. I donno..I am a bit confused...
promila singh
Greenhorn

Joined: Jan 15, 2007
Posts: 24
yes you can have final methods in abstract class
try this code
abstract class abstractclass
{
final public void display(){
System.out.println("Display");
}
abstract void show();
}
public class extendedclass extends abstractclass{
public static void main(String args[]){
array aa = new array();
aa.display();
aa.show();
}
public void show(){
System.out.println("show");
}
}

SCJP 6.0 Preparing for SCWCD
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Promila, please use code tags.

http://faq.javaranch.com/java/UseCodeTags
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Ok, Now I figured out. That when a subclass extends an abstract class, it inherits its methods(final also). Its only when you try to override the inherited final methods, when you get a Compiler error. Should have thought about it earlier ops: .
promila singh
Greenhorn

Joined: Jan 15, 2007
Posts: 24
m new here
thanks abhi vijay
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Abhi remember, abstract class cannot have:

1) abstract final methods.
2) private abstract methods.
3) native abstract methods.
4) abstract synchronized methods.
5) strictfp native methods.

abstract class can have:

1) private native methods
2) synchronized methods with body
3) protected abstract methods
4) private static synchronized native methods.


SCJP 6
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Punit, To my Rescue Again
 
GeeCON Prague 2014
 
subject: Final methods