• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

A class is a subclass of itself?

 
Ranch Hand
Posts: 74
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi..Everyone!
how can it be possible that a class is a subclass of itself?....i am getting confuse with this statement ...can anybody explain about this...?
please reply me...
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Inheritance represents IS-A relationship. Since a class IS itself, it cannot inherit itself. Even if you try to implement it (class A extends A) you will get compile time error.
This is more of a theoretical question, and I would point you to this post for further explanation.
 
Marshal
Posts: 76394
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to read the Java Language Specification for the official definition, but it may be difficult to read. I think you will find it calls a class a subtype of itself.

It is also a supertype of itself. But not a superclass or subclass. At least I think that is what you will find.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kemal Sokolovic,
Your post was moved to a new topic.
 
Master Rancher
Posts: 4268
57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JLS is more confusing than usual on this topic. Campbell summarizes it correctly - the supertypes and subtypes of a class include the class itself, but the superclasses and subclasses do not. Which seems stylistically inconsistent, but logically consistent, in the sense that the JLS does use the terms precisely and consistently, even if they seem inconsistent.

So if you're using the JLS definitions, a class is not a subclass of itself, but it is a subtype of itself.

If you're using some other definitions, well, the answer would depend on the definitions used.
 
I promise I will be the best, most loyal friend ever! All for this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic