aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Abstract class being extend by another abstract class, and finally being extends by a concrete class 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 "Abstract class being extend by another abstract class, and finally being extends by a concrete class" Watch "Abstract class being extend by another abstract class, and finally being extends by a concrete class" New topic
Author

Abstract class being extend by another abstract class, and finally being extends by a concrete class

Yin Stadfield
Ranch Hand

Joined: Oct 13, 2012
Posts: 35

Here it is:

Thanks.
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

Do I need to still repeat the abstract methods definition declared in the superclass to this class?


no you don't need to unless you want to provide an implementation for them. you can repeat them if you want but it will be like overriding without actually providing an implementation.


If my understanding is correct, I need to implement here goForward, reverse, turn, anotherAbstract1 and anotherAbstract2, is it right?


yes you are right. a concrete class has to implement all the abstract method it inherits.

Yin Stadfield
Ranch Hand

Joined: Oct 13, 2012
Posts: 35

gurpeet singh wrote:
Do I need to still repeat the abstract methods definition declared in the superclass to this class?


no you don't need to unless you want to provide an implementation for them. you can repeat them if you want but it will be like overriding without actually providing an implementation.



So I can extend an abstract class with an abstract class and I can choose if I want to provide implementation or just leave them to the superclass?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18717
    
  40

Yin Stadfield wrote:
gurpeet singh wrote:
Do I need to still repeat the abstract methods definition declared in the superclass to this class?


no you don't need to unless you want to provide an implementation for them. you can repeat them if you want but it will be like overriding without actually providing an implementation.



So I can extend an abstract class with an abstract class and I can choose if I want to provide implementation or just leave them to the superclass?



What happened when you tried it? Do you get compilation errors? ... Hands on learning, ie. just try it out, is arguably good here.

Henry


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

Joined: Apr 04, 2012
Posts: 924
    
    1

you can extend an abstract class with an abstract class and choose to provide implementation of all, any or none of the abstract methods. it can be possible that you declare the subclass as abstract but implementetd all the methods, or you implemented few of the methods or none of the methods. ultimately there has to be a concrete class which implements all the methods .
Yin Stadfield
Ranch Hand

Joined: Oct 13, 2012
Posts: 35

Henry Wong wrote:
Yin Stadfield wrote:
gurpeet singh wrote:
Do I need to still repeat the abstract methods definition declared in the superclass to this class?


no you don't need to unless you want to provide an implementation for them. you can repeat them if you want but it will be like overriding without actually providing an implementation.



So I can extend an abstract class with an abstract class and I can choose if I want to provide implementation or just leave them to the superclass?



What happened when you tried it? Do you get compilation errors? ... Hands on learning, ie. just try it out, is arguably good here.

Henry




Thanks, and I did tried it out now as you said.
What Gurpeet said was right. Just a question though because while I was trying it out, the compiler seems not to be strict with parameters name when you implement them from the superclass. Why is that so? I changed the void turn(int whichType) to void turn(int fasd), and the compiler is good with that.
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

Parameter names does not matter. what matters is that rules of the overriding must be followed. and as per rules the name of method should be same and the parameter types should be of the same type. also the return type should be same or as of java 5 they should be of COVARIANT types.

also you need to keep in mind that overridding happens in context of inheritance. or you can say it is related to inheritance. if a method is accessbile in subclass then only you can override it with your sublcass specific implementation. what it means is that if you have

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Abstract class being extend by another abstract class, and finally being extends by a concrete class