• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Kotlin inheritance vs abstraction

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I studied in kotlin inheritance, sub classes with inherit from super class, the instance of super class is created.
In abstraction, the instantiation can be avoided when "abstract" keyword is used instead of "open". While abstract properties/functions in abstract class doesn't have to be instatiated, an abstract class can have non abstract properties/functions with body.

Question 1: If class is not instiantiated, how are the non-abstract properties/functions of abstract class are valid / accessed?
Question 2: If abstract class cannot be instantiated, why does it even need a constructor? Why not remove constructor like interface doesn't have?
 
Ranch Hand
Posts: 180
1
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the short answer is the subclasses which inherit from the abstract class can call these methods and also the abstract constructor.
 
aj Haasan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for reply. Because only subclasses that can be instantiated can access parent abstract super class, we dont need worry about calling on parent anstract object. correct? Which mean an object is never created from abstract parent class as abstract class cant be instatiated? Is my understanding correct?
 
Salil Wadnerkar
Ranch Hand
Posts: 180
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, correct.
 
reply
    Bookmark Topic Watch Topic
  • New Topic