Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Is this debugging case a downcast case?

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Bartender
Posts: 2908
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.




 
Marshal
Posts: 5409
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic