This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Extends class  RSS feed

 
Gabriel Turmic
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there, I am new in java and I have some problems with class inheritance
superclass:


Child class:



Main method:


Problem is that c3.rezultat2(); print 0.0. Where am i wrong?
 
Tim Moores
Saloon Keeper
Posts: 3885
91
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
n1 and n2 in clasa2 are never assigned a value, so they retain their default value, which is 0.0

Those variables have nothing to do with those in the main method that do get assigned values.
 
Gabriel Turmic
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My mistake:


Now works fine. Thanks.
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I think the real mistake you made was not giving that class a constructorThat makes it impossible to create a clasa2 object without passing the information for x and y.
You should also make all fields private (except global constants) and allow access to them via getXXX and maybe setXXX methods.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!