Kosta 클라우드 네이티브 애플리케이션 개발 (CNA) 교육 14일차

2024. 12. 5. 17:42Kosta 클라우드 네이티브 어플리케이션 개발(CNA) 교육

JAVA

package com.lec;

import com.lec.comm.chap07_comm1;

class parent {
	public static void pMethod() {
		System.out.println("Parent Class PMethod Call");
	}
}

/*
 ************************************************************************** 
 * 오버 라이딩
 * 
 * (상속) 관계의 두 클래스에서 부모의 메서드를 자식이 가져다 쓰는 것
 * 선언부는 그대로, 바디를 변경
 * 접근제어자는 부모보다 같거나 커진다
 * 예외처리는 같거나 작아진다
 * ************************************************************************* 
 */

class parent2 extends parent{
	
	public static void pMethod() {
		System.out.println("Parent2 Class PMethod Call");
	}
}

// 상속은 수정 가능
// 단일상속 : 클래스(자식) extends 클래스(부모)
// 다중상속 : 클래시(자식)  implements 인터페이스(부모), 인터페이스(부모), ...
//			  인터페이스(자식) extends 인터페이스(부모), 인터페이스(부모), ...

class parent3{
	int x = 3;
}

class Child extends parent3{
	
}

public class chap07_childern extends parent2{

	/*
	 ******************************************************
	 *
	 * public : 모든 접근 허용 
	 * default : 같은 패키지 내 접근 허용, 다른패키지(자식) 허용 
	 * protected : 같은 패키지 내
	 * 접근 허용 private : 같은 클래스 내 접근 허용
	 * 
	 ****************************************************** 
	 */

	// public 가 붙은 class 는 파일에 단 하나만 존재
	public static void main(String[] args) {
		
		
		chap07_comm1 comm1 = new chap07_comm1();
		comm1.add(1, 2);
		
		pMethod();
		
		
	}
}
public class chap07_comm1 {

	public int add(int a, int b) {
		System.out.println("Comm 1번 출력 Call");
		return a + b;
	}

}

 

public class chap07_comm2 {

	public int add(int a, int b) {
		System.out.println("Comm 2번 출력 Call");
		return a + b;
	}
	public void myPrint() {
		System.out.println("Comm 2번 Print Call");
	}

}

class Point {
	int x;
	int y;

	Point(int x, int y) {
		this.x = x;
		this.y = y;
	}

	String getLocation() {
		return "x :" + x + ", y : " + y;
	}
}

class Point3D extends Point {
	int z;

	Point3D(int x, int y, int z) {
		// super(), 빈칸 시 에러
		// super () 에 값을 넣어줘야지만 된다
		super(1,1);
		this.x = x;
		this.y = y;
		this.z = z;
	}

	String getLocation() {
		return "x :" + x + ", y : "+ y + ", z : " + z;
	}
}