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

One query about inheritance ??  RSS feed

 
Bikash Paul
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There is three independent class A ,B & C . Is it possible to get the properties of A and B class in class C without creating object and without extending those A & B class.If possible can any one please give me a small example.

I heard that one Container class is available for that but i couldn't find any document on that.

Thanks & Regards
Bikash
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If A & B are independent classes, then there is no way in Java for C to inherit the properties of both classes. Java only implements single inheritance - in your case, that means that C can inherit from A or B, but not both.

If A & B are interfaces and not classes, then C can implement both of them and obtain something like multiple inheritance.
 
Jeremy Thornton
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If you really want to use A and B without creating objects you can use static methods or attributes. These belong to the class rather than any particular instance.

e.g.


Hope this helps,
Jeremy.

[ edited to fix broken code tags -ds ]
[ May 17, 2004: Message edited by: Dirk Schreckmann ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I heard that one Container class is available for that but i couldn't find any document on that.

Just to be clear, there is no such Container class.
 
Bikash Paul
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Lots of thanks for all yours clarification.

Thanks & Regards
Bikash
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!