Inheritance
Inheritance enables you to reuse code that has already been defined by a class.
Inheritance in Java is a concept that acquires the *properties from one class to other classes.
*properties are variables in a class.
For example:
public class Employee {
private String name;
private int salary;
public getName() {
return this.name
}
}
In the class above, name and salary are properties of an instance of the class (object of the class) while getName() is a method.
// class child(subclass) extends parent(superclass) {}
class Parent {}
class Child extends Parent {}
A subclass inherites all the members (*fields, methods, and nested classes) from its superclass.
*A field is a class, interface, or enum with an associated value.
class Point {
int x;
int y;
}
// case 1.
class Point3D {
int x;
int y;
int z;
}
// case 2.
class Point3D extends Point {
int z;
}
*Both case 1 and case 2 have 3 members in the address being pointed to by the reference variable.
*reference variable is one that refers to the address of another variable. (참조변수)
상속의 단점
https://tecoble.techcourse.co.kr/post/2020-05-18-inheritance-vs-composition/