• Post Reply Bookmark Topic Watch Topic
  • New Topic

Meaning the subclass  RSS feed

 
Ranch Hand
Posts: 406
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The term subclass is richer than the term superclass because this can contains many methods than the superclass term.

What do you think?
 
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am never happy with the sort of inheritance because the methods may not be accessible from the reference:-The chargeFare method is not in the Car class, so the last line will fail to compile.
 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anda Cristea wrote:Hi,

The term subclass is richer than the term superclass because this can contains many methods than the superclass term.

What do you think?


What were you taught? What was discussed in your class? If I wanted to be picky, I'd say the statement isn't very clear. Why does it refer the "the term subclass"?  By analogy, would I also say "The term actor is richer than performer because an actor is paid more money"? And what does the word "richer" mean in this context and does it follow that having more methods makes one class "richer" than another class?
 
Dana Ucaed
Ranch Hand
Posts: 406
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confusing regarding this term  subclass.
But probably I must think from top down if I draw inheritance tree.

Subclass is more specific and may have several methods than superclass.

It is to hard to imagine inheritance tree or UML diagrams.
 
Campbell Ritchie
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anda Cristea wrote:. . . It is to hard to imagine inheritance tree or UML diagrams.
There is no need to imagine an inheritance tree. You can see one easily by looking at this API documentation page. You can see which types that sort of Exception is a subtype of (including interfaces), and you can see which subtypes it has. If you go up and down the list of classes at the top of the page, you will see that different types have more, or fewer, subtypes. You can find new methods for one sort of Exception, but most exceptions do not have more methods than their supertypes, so that methods link shows only methods inherited from supertypes.
With the exception of java.lang.Object, all classes in the API have an inheritance hierarchy shown in their API documentation.
You can find inheritance trees drawn differently, for example here in the Java™ Tutorials.
 
Dana Ucaed
Ranch Hand
Posts: 406
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes richer means many methods and instance variables.

It does not seem suggestively the name subclass.

In my opinion it would be suggestive child instead subclass.

Probably I am very picky. :-)

 
Campbell Ritchie
Marshal
Posts: 56608
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anda Cristea wrote:. . . child instead subclass. . . .
No, because computer inheritance, biological inheritance and money inheritance are different from one another. So saying parent class and child class is misleading, even though many people are taught like that.
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Campbell: Inheritance in object oriented programming does not mean the same thing as in biology. So talking about a "parent class" and a "child class" is indeed misleading.

In OO programming, inheritance means specialization, and there is an "is a" relationship between the subclass and the superclass.

So, a subclass is a special kind of its superclass. For example, imagine that you have a class Animal with subclasses Cat and Dog.

A Cat is a special kind of Animal.
A Dog is a special kind of Animal.

Note the difference with biological inheritance. If you have a class Parent and a class Child extends Parent, then what you are saying is "a Child is a special kind of Parent". Which is incorrect.

Look at the classes in the standard Java library, and you'll see that this works for many classes. For example:

Every class extends java.lang.Object, so every class is a special kind of Object.

Class Integer extends Number because an Integer is a special kind of Number.
Class Double extends Number because a Double is a special kind of Number.

Class ArrayList extends AbstractList, which extends AbstractCollection, because an ArrayList is a special kind of AbstractList which is a special kind of AbstractCollection.

Class SimpleDateFormat extends DateFormat because a SimpleDateFormat is a special kind of DateFormat.

Etc.
 
Dana Ucaed
Ranch Hand
Posts: 406
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In specification java language I read about term subtype and It seems to me correct and sugestive.

 
Campbell Ritchie
Marshal
Posts: 56608
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The wo‍rd subtype has a broader meaning than subclass. A class can be a subtype of an interface and an interface can be a subtype of another interface.
A class can be a subclass of (in Java® one) other class, its superclass.
The C# people talk about base types and derived types, not terms used in Java®, but maybe they are good terms.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:...base types and derived types, not terms used in Java®, but maybe they are good terms.

I could buy in to that. 

I like what generalization-specialization suggests but it's always a mouthful.
 
Dana Ucaed
Ranch Hand
Posts: 406
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your answers!

I am confused about the terms : superclass and subclass.

I like the Microsoft terms : base class and derived class.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!