Key Difference – Superclassvs Subclass
InObject Oriented Programming(OOP),该系统是使用objects.这se objects are created using a班级.一个类是一个蓝图or a description to create an object. Object creation is also known as object instantiation. Each object is communicating with other objects. A program or software can be developed using Object Oriented Programming.Inheritance是OOP中的主要概念。它改善了代码可重复性。它不是从一开始就实现程序,而是允许将已经存在的类的属性和方法继承到新类。它有助于使程序更易于管理。超类和子类是与继承有关的两个术语。本文讨论了超类和子类之间的差异。这key differencebetween the Superclass and Subclass is thatSuperclass is the existing class from which the new classes are derived while Subclass is the new class that inherits the properties and methods of the Superclass.
内容
1.Overview and Key Difference
2.什么是超级类
3.What is Subclass
4.Similarities Between Superclass and Subclass
5.Side by Side Comparison – Superclass vs Subclass in Tabular Form
6。概括
什么是超级类?
在继承中,新类得出的现有类称为超类。它也称为父级或基类。
有不同的继承类型。使用以下示例进行了说明。将B和C视为课程。
根据上图,超类别与每种继承类型不同。在单层继承中,A是超类。在多级继承中,a是B和B的超类是C的超类。在层次结构的继承a是B和C的超类。在多个继承中,A和B都是C的超级类别。
Hybrid inheritance is a combination ofmulti-level and multiple inheritances.In the left-hand side diagram, A is the Superclass for B, C and B, C are the Superclasses for D. In the right-hand side diagram, A is the Superclass for B and B, D are Superclasses for C.
Refer the below program written in Java.
According to the above program, class A have sum() and sub() methods. Class B has multiply() method. Class B is extending class A. Therefore, properties and methods of class A are accessible by class B. Therefore, class A is the Superclass. The reference type of class B is taken to create the object. So, all methods such as sum(), sub() and multiply() are accessible by the object. If Superclass reference type is used for object creation, the members of class B cannot be accessible. e.g. A obj = new B(); Therefore, Superclass reference cannot call the method multiply() because that method belongs to class B.
What is Subclass?
According to the above diagrams, Subclasses varies from each inheritance type. In Single Inheritance, B is the Subclass. In multi-level inheritance, B is the Subclass of A and C is the Subclass of B. In Hierarchical Inheritance B and C are Subclasses of A. In multiple inheritances, C is the Subclass for A and B.
In Hybrid inheritance, the diagram in the left, B and C are Subclasses of A. D is the Subclass of B and C. In the diagram to the right, B is the Subclass for A. C is the Subclass of B and D.
According to the above Inheritance program, class B is extending class A. Therefore, all properties and methods of class A are accessible by class B. Class B is the new class that inherits from class A. It is known as the Subclass. It is also known as the child class or derived class. Class B has multiply () method and it can also access sum() and sub() methods of class A using inheritance.
What is the Similarity Between Superclass and Subclass?
- Both are related to Inheritance.
超类和子类有什么区别?
超类与子类 |
|
实施继承时,新类的现有类是超类。 | When implementing inheritance, the class that inherits the properties and methods from the Superclass is the Subclass. |
Synonyms | |
Superclass is known as base class, parent class. | 子类被称为派生类,儿童班。 |
功能 | |
A superclass cannot use the properties and methods of the Subclass. | A subclass can use the properties and methods of the Superclass. |
Single-Level-Inheritance | |
有一个超类。 | 有一个子类。 |
Hierarchical Inheritance | |
这re is one Superclass | 这re are many Subclasses. |
多元继承 | |
这re are many Superclasses. | 有一个子类。 |
概括– Superclassvs Subclass
继承是OOP的概念。它允许使用新类访问现有类的属性和方法。继承的类是超级类,派生类是子类。超类和子类之间的区别在于,超类是从中得出新类的现有类,而子类是继承超级类的属性和方法的新类。
Download the PDF Superclass vs Subclass
You can download PDF version of this article and use it for offline purposes as per citation note. Please download PDF version hereDifference Between Superclass and Subclass
Reference:
1.“Inheritance in Java – Javatpoint.”这Point,Available here
2.tutorialspoint.com. “Java Inheritance.”这Point,Available here
发表评论