• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is this debugging case a downcast case?  RSS feed

 
Antoine Compagnie
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to improve my debugging skill so I collected some exercises of bad programmed code and I try to fix them.



I said that in main there would be a problem as far as there is a lack of argument for the constructor of Tourisme and a Vehicule cannot be a Tourisme, it can only becomes a Transport.
So I would rather write in the main:



That fits with the argumentes necessited but Eclipse still doesn't want my code...
What did I missed? I'm okay with hints if you think it can help me improve my skills...
 
salvin francis
Bartender
Posts: 1664
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't concentrate on the Test class as well as Tourisme class right now...
Lets break your code into small units for you to understand well.

As you probably know, the constructors of the Base class are invoked first when creating a new Subclass object.

This code below wont compile till you add a line of code to make it work.




 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Antoine, welcome to the Ranch!

A little admin matter. Please BeForthrightWhenCrossPostingToOtherSites. We don't mind if you do crosspost, but we do ask that you state that you have done so and link to where.

Crosspost: http://www.java-forums.org/advanced-java/95562-cas-case-polymorphism-downcasting.html
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Antoine Compagnie wrote:I said that in main there would be a problem as far as there is a lack of argument for the constructor of Tourisme and a Vehicule cannot be a Tourisme, it can only becomes a Transport.


The first bit is correct, you have too few parameters supplied to the Tourisme constructor.

The second part is not.
A Tourisme object IS-A Vehicule object, and so a Tourisme reference can be assigned to a Vehicule reference.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!