This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes A class is a subclass of itself? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "A class is a subclass of itself?" Watch "A class is a subclass of itself?" New topic
Author

A class is a subclass of itself?

viki Bhardwaj
Ranch Hand

Joined: Nov 07, 2011
Posts: 74


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...
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

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.


The quieter you are, the more you are able to hear.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
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.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Kemal Sokolovic,
Your post was moved to a new topic.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3003
    
    9
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: A class is a subclass of itself?
 
Similar Threads
class
Prevent cloning in subclasses
can we overrding a method in a class itself
java class
Doubt