자바의 상속
4475 단어 computerscienceoopjava
자바와 상속
상속은 하나의 객체가 상위 객체의 기능(메서드 및 필드)을 상속하는 Java의 메커니즘입니다. 상속은 OOP(객체 지향 프로그래밍 시스템)의 중요한 기둥입니다. 상속은 IS-A 관계를 나타냅니다.
술어
하위 클래스: 다른 클래스의 기능을 상속하는 클래스를 하위 클래스라고 합니다. 확장 클래스, 파생 클래스 또는 자식 클래스라고도 합니다. 하위 클래스는 새 메서드와 필드도 추가할 수 있습니다.
수퍼 클래스: 다른 클래스에 의해 상속되는 클래스를 수퍼 클래스라고 합니다. 기본 클래스 또는 상위 클래스라고도 합니다.
통사론:
class derived-class extends base-class
{
//methods and fields
}
예시

구현
class Person{
String name= "John";
}
class Employee extends Person{
float salary = 10000;
public static void main(String args[]){
Employee e =new Employee();
System.out.println("Name of Employee is:"+ e.name);
System.out.println("Salary of Employee is:"+ e.salary);
}
}
상속의 종류
class derived-class extends base-class
{
//methods and fields
}

구현
class Person{
String name= "John";
}
class Employee extends Person{
float salary = 10000;
public static void main(String args[]){
Employee e =new Employee();
System.out.println("Name of Employee is:"+ e.name);
System.out.println("Salary of Employee is:"+ e.salary);
}
}
상속의 종류
class Person{
String name= "John";
}
class Employee extends Person{
float salary = 10000;
public static void main(String args[]){
Employee e =new Employee();
System.out.println("Name of Employee is:"+ e.name);
System.out.println("Salary of Employee is:"+ e.salary);
}
}





결론
이 기사가 Java에서 상속을 배우는 데 도움이 되기를 바랍니다.
Reference
이 문제에 관하여(자바의 상속), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://dev.to/ritul120/inheritance-in-java-5f54
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(자바의 상속), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/ritul120/inheritance-in-java-5f54텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)