• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing superclass parameters  RSS feed

 
Ranch Hand
Posts: 143
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Soooo...I was rather proud of myself I got as far as I did with this until now. My understanding was I could override a method from the superclass, including with
different parameters, but when I try to use super. it gives me an error the arguments have to match the superclass. But, if I do that it won't make any sense.

The first code below is the superclass. The issue I'm having is on the second code at lines 7 and 10. Am I just doing it all wrong? Any advice? The ultimate
goal is to make a new class where I'm able to display various packages with or without insurance.





 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan Bishop wrote:My understanding was I could override a method from the superclass, including with different parameters

Afraid not. Overriding involves methods with the same signature - including number and type of parameters. If the signature is different then it's overloading.

Ryan Bishop wrote:when I try to use super. it gives me an error the arguments have to match the superclass. But, if I do that it won't make any sense.

Why not ? The second parameter is the method. How can you calculate the cost if you don't know the shipping method ?
 
Ryan Bishop
Ranch Hand
Posts: 143
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like this?

 
Ranch Hand
Posts: 48
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes this is correct.

super.calculateCost(newCost);


this method is not available in the super class.
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should find out about the Override annotation and use it every time you think you are overriding a method. It does not behave exactly according to the official definition of overriding, however.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!