The difference between the parent class and the superclass

Is there a difference between a parent class and a superclass? Is a superclass just a parent class that does not inherit from other classes?

+11
source share
5 answers

This is more a difference in terminology, the idea of ​​parent and child classes or super and subclasses. It seems that this depends on your experience with the programming language and subject area, on which one you use, and also when you first started to engage in object-oriented programming.

In both cases, there is a class, a parent class, or a superclass, or a base class from which other classes, a child class, or a subclass originate. A child class or subclass extends the parent class or superclass by adding some capability to the existing capability of the extensible class.

super() is a way to create a parent or superclass for a Java class in a derived class.

In the early years of object-oriented programming, there was a significant outflow of terminology, since different people worked in this area, published articles and books, and developed object-oriented languages. All this was quite new and exciting, and people tried to choose the right vocabulary to use different words and phrases to express object-oriented concepts.

And thanks to a number of object-oriented programming languages ​​that were developed and gained popularity, a community with a certain dictionary arose around the language. Therefore, older and more experienced programmers, who used to be object-oriented, may call things a little differently.

Parent and child are also used to describe other types of Is-A or Has-A relationships. For example, the parent window and the child window are also used for window systems in which the window, the child, is contained in another window, the parent. So, the parent window has a child window.

+5
source

These are different terms for solving the same concept of OOP: inheritance. If the ChildClass continues with the ParentClass , you can say:

  • ChildClass parent class - ParentClass
  • ParentClass is a superclass of ChildClass

Inheritance levels have nothing to do with it, it does not matter if the Superclass itself extends another class.

+3
source

I would say the same thing.

You might want to distinguish between direct and indirect parent or superclass, but I think both of these terms are also not clear enough. So, if this is what you are trying to express, it is better to be explicit.

In addition, in many programming languages, the keyword "super" is used to refer to a single direct parent class. But even there, if you call the "super" method, and the direct parent does not implement it, it also bubbles up.

+2
source

They are essentially the same. Depending on the language, the terminology changes. A parent can mean an immediate parent, while a Super class can mean any of the ancestor classes. In addition, in java, there is a super () method that calls the parent constructor.

0
source

In Ruby, we have both concepts that mean different things.

ParentClass -> ChildClass used to place names

and

SuperClass -> SubClass this is used for inheritance

Examples below:

ParentClass -> ChildClass

 class A def self.f1 puts "A -> #{self.name}.f1 called" end # B is childclass of A class B def self.f2 puts "B -> #{self.name}.f2 called" end end end # C is subclass of A class C < A def self.f3 puts "C -> #{self.name}.f3 called" B.f2 end end 

See the result below:

  • C.f1

A → C.f1 is called

  1. C.f3

C → C.f3, called

B → A :: B.f2 is called

-1
source

All Articles