File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Abstract doubts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Abstract doubts" Watch "Abstract doubts" New topic

Abstract doubts

João Martinho

Joined: Aug 26, 2009
Posts: 12

I'm starting to study for my SCJP and i'm right at the begining, i'm reading SCJP for java 6 by Kathy and Bert.

Now my doubt, on page 49 of the book we learning about Abstract Methods:
abstract Car ->class
startEngine( )
abstract goForward( )
abstract reverse( )
stop( )
abstract turn(int whichWay)

then we have two implementations which only one makes me have doubts:

abstract SUV ->class
enable4wd( )
goForward( )
reverse( )
abstract goOffRoad( )
//turn( )not implemented

AcmeRover -> Class
enable4wd( )//optional
goOffRoad( )//Required
turn(int whichWay)//Required

So i have one totally abstract class abstract Car no method is implemented then we implment anothe Abstract class abstract SUV so far so good since it's also abstract so no need to implement nothing.

But then we have class AcmeRover first concrete classe so it has to implement all the abstract members that aren't implemented till then, so for me it would need to implement:
startEngine( ) -> from Car class
abstract goForward( ) -> from Car class
abstract reverse( ) -> from Car class
stop( ) -> from Car class
abstract turn(int whichWay) -> from Car class

but also:

enable4wd( )-> from SUV class
goForward( )-> from SUV class
reverse( )-> from SUV class
abstract goOffRoad( )-> from SUV class
turn( )-> from SUV class

why? because iven if it's not explicit that all methods are abstracted, they are declare and end with () so not implemented which i think is implicit, also since the package is not stated i assume they are on the same so even with Default access the all methods are visible to the concrete class.
Ankit Garg

Joined: Aug 03, 2008
Posts: 9327

I couldn't understand your problem properly, but if there is an abstract class, then all the methods in it are not implicitly abstract. A method in an abstract class is abstract only if it is declared so and there is no method body. look at this code

In the above code Sub is not required to define any method as Super class has no abstract methods. Now look at this code

In the above code if you don't define method1 in Sub class, then Sub class itself will be abstract. Now coming to your situation

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg

Joined: Aug 03, 2008
Posts: 9327

And João welcome to javaranch
João Martinho

Joined: Aug 26, 2009
Posts: 12
Ok i have re-read your answer so my only problem is that i didn't understand that all methods not marked as Abstract are already implemented, even if they finish, on the book, with () is this right?

But that could lead to a misunderstand on a tricky question on the real exam right?

Lets see if at third time is the last time:

I need to thank you Ankit Garg, and all of the JavaRanch community for making java much easier for everyone.

now, if i get this right the only "problem" on your code is that you forget to stated (extends SUV):

Or i wouldn't need to implement anything right?

Sorry but i was thinking one way and i read you answer other way

João Martinho

Joined: Aug 26, 2009
Posts: 12
Finally i read the code and understand what you and the book are stating/implementing.

thank you
I agree. Here's the link:
subject: Abstract doubts