• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

inheritance, extended class.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to complete my exercise but I have issues in it. I would be very grateful if you help me.

Here is my abstract Boat class.





Here is my extended class SailBoat.



and here is my driver class.

 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you have an actual question ?
TellTheDetails
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And the question / problem is?

Welcome to the Ranch!
 
Ranch Hand
Posts: 198
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mohamed Suood wrote:
boatList[0].setMastHeight(12); // <<=== something is woring here in this line.



The issue is... setMastHeight(12) method is not a method of Boat class, and your instance is of a Boat class. Hence the issue.
If you want to set setMastHeight, you need to use the instace of SailBoat class.
 
Marshal
Posts: 79716
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
Consider adding a setMastHeight method to the Boat class. If Boat is abstract, the method can be abstract, too.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prabhakar Reddy Bokka wrote:and your instance is of a Boat class.


To be more precise the reference variable is of type Boat and that is what is used to determine what methods can be called.
The instance is actually a SailBoat object.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Consider adding a setMastHeight method to the Boat class. If Boat is abstract, the method can be abstract, too.


But not all boats have masts, so that would not be a good design.

If you want to add a SailBoat instance to the array, you need to create it separately and then add it
e.g.

Alternatively you could have a constructor that sets all the variables as you appear to have with your MotorBoat class.

Or a third alternative is to use the Builder pattern.
 
They weren't very bright, but they were very, very big. Ad contrast:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic