• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Abstract doubts

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And João welcome to javaranch
 
João Martinho
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally i read the code and understand what you and the book are stating/implementing.

thank you
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic