Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

when to use the supperclass object and when to use subclass object?  RSS feed

 
Vishal Kurkure
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
example 1.

example 2.


both produce the same output but i am confused bit when to use superclass obejct or subclass object?
 
Fred Kleinschmidt
Bartender
Posts: 560
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They both output the same thing because the both execute the same fun() method. Try adding this to the xyz class:


You can also try this in main:
and see what happens.

NOTE: You should get into the habit of following standard conventions and naming your classes beginning with a capital letter.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!