Frog is cry
super(day20) 본문
package day21.ex02_super;
public class Student extends People{
public int studentNo;
// 아래는 자식 클래스의 명시적 생성자임
public Student(String name, String ssn, int StudentNo) {
super(name, ssn);
this.studentNo = StudentNo;
}
}
package day21.ex02_super;
public class Student_Ex {
public static void main(String[] args) {
Student std = new Student("홍길동", "123456-1234567", 1);
System.out.println("name : " + std.name);
System.out.println("ssn : " + std.ssn);
System.out.println("studentNo : " + std.studentNo);
}
}
package day21.ex02_super;
public class Tv extends Product{
Tv(){}
public String toString() {
return "Tv";
}
}
package day21.ex02_super;
public class Tv_Ex {
public static void main(String[] args) {
Tv t = new Tv();
System.out.println(t.toString());
}
}
package day21.ex02_super;
public class Car {
String name;
int wheel;
}
package day21.ex02_super;
public class SportsCar extends Car{
String color;
void CarSet(String name, int wheel) {
this.name = name;
this.wheel = wheel;
}
}
package day21.ex02_super;
public class SportsCar_Ex {
public static void main(String[] args) {
SportsCar c1 = new SportsCar();
// c1.name = "그랜저"; // 부모
// c1.wheel = 4; // 부모
c1.CarSet("그랜저", 4); //부모
c1.color = "검정색"; // 자식
System.out.println("부모 : " + c1.name);
System.out.println("부모 : " + c1.wheel);
System.out.println("자식 : " + c1.color);
}
}
package day21.ex03;
public class Car {
String color;
int speed;
void upSpeed(int value) {
speed = speed + value;
}
void downSpeed(int value) {
speed = speed + value;
}
}
package day21.ex03;
public class Car_Ex {
public static void main(String[] args) {
Sedan se = new Sedan();
Truck tr = new Truck();
se.upSpeed(300);
tr.upSpeed(100);
se.seatNum= 5;
tr.capacity = 50;
int i = tr.getCapacity();
System.out.println("승용차 속도는" + se.speed + "km, 좌석수는 " + se.getseatNum() + "개 입니다.");
System.out.println("트럭 속도는 " + tr.speed + "km, 적재량은" + tr.getCapacity() + "톤입니다.");
}
}
package day21.ex03;
public class Truck extends Car{
int capacity;
// void
// 매개타입 메소드이름(매개변수(지역변수)) {
// capacity = 매개변수
//}
int getCapacity() {
System.out.println("안녕하세요");
return capacity;
}
}
package day21.ex03;
public class Sedan extends Car{
int seatNum;
int getseatNum() {
return seatNum;
}
}
'JAVA > 국비수업' 카테고리의 다른 글
final(day21) (0) | 2020.07.28 |
---|---|
오버라이딩(day20) (0) | 2020.07.27 |
상속(day20) (0) | 2020.07.27 |
이전복습 (day19) (0) | 2020.07.24 |
getter_setter(day19) (0) | 2020.07.24 |
Comments