상속 4

java 클래스 구현, 상속, 자동차 예제

//Car.java public class Car { private String carname; //차 이름 protected int speed; //차 속도를 수정해야하기 때문에 protected public Car() {} public Car(String carname) //생성자 { this.carname = carname; //차 이름 this.speed = 100; //차 속도 설정 (100이 기본) } public String getName() { return this.carname; } public int getSpeed() { return this.speed; } public void setSpeedUp() { speed += 10; } public void setSpeedDown() { ..

Java 2021.10.21

java 상속 관계 구조 구현(학생 예제)

//Student.java public class Student { private String student_name; //학생 이름 private int computer_grade; //컴퓨터 점수 public Student() {} public Student(String student_name, int computer_grade) //생성자 { this.student_name = student_name; //학생 이름 this.computer_grade = computer_grade; //컴퓨터 성적 설정 } public String getName() { return this.student_name; } public int getAverage() { return this.computer_grade; ..

Java 2021.10.21

C++ 상속 관계 구조 구현 (학생 예제)

#include #include #include #include // 배열 5개만 using namespace std; class Student { private: char *student_name; //학생 이름 변수 int computer_grade; public: Student() {} Student(const char *_student_name, const int _computer_grade) //이름 입력받기 위한 생성자 { student_name = new char[strlen(_student_name) + 1]; //NULL문자 포함한 배열 선언 strcpy(student_name, _student_name); //student_name _student_name 입력 //cout

C++ 2021.10.21