JAVA - C++에서의 상속
본문 바로가기
CS Study/JAVA

JAVA - C++에서의 상속

by KyeongMin 2019. 12. 21.
728x90
반응형
#include<stdio.h>
#include<iostream>
using namespace std;
class Parent {
public:
	int age;
	char name[11];
	Parent() {}
		Parent(int age, const char name[11]) {
			printf("나이 : %d, 이름 : %s\n", age, name);
		}
};
class Child : public Parent {
public :
	int weight;
	int height;
	Child(){}
	Child(int age, const char name[11], int weight, int height) {
		this->age = age;
		strcpy(this->name, name);
		this->weight = weight;
		this->height = height;
		printf("나이 : %d, 이름 : %s, 몸무게 : %d, 키 : %d", this->age, this->name, this->weight, this->height);
	}
};
int main(void) {
	Parent parent(20, "3DPIT");
	Child child1(30, "4DPIT", 73, 178);
	return 0;
}

c++에서 상속하는것인데 자바상속이라 비교해서 보면 좋을것 같아서 글 올립니다. 

자바상속이 궁금하신분은 아래 링크를 들어가서 봐주세요.

2019/12/04 - [JAVA] - 자바복습 - 클래스의 상속

2019/12/07 - [JAVA] - 자바복습 - 클래스 상속, 오버라이딩

2019/12/08 - [JAVA] - 자바복습 - 상속의 목적

728x90
반응형

댓글