정보처리기사/[흥달쌤] 실기_JAVA 특강 (완) 7

JAVA특강 / 07. 추상클래스&Interface

1. 추상클래스&Interface의 개념 - 추상클래스 : 반드시 오버라이딩해서 사용할 미완성의 메서드 하나이상 가진 미완성 클래스, 객체생성x - Interface : 추상클래스의 극단으로 모든 메서드가 추상적인 상태 2. 추상클래스 정의와 사용 abstract class Remote{ public int volume = 10; public int channel = 1; public void volume_up(){//완성된 메서드 this.volume++; } public void volume_down(){//완성된 메서드 this.volume--; } abstract void channel_change(int i); } class TV_Remote extends Remote{//미완성 클래스는 상속해..

JAVA특강 / 06. Static

1. Static의 개념 : 모든 인스턴스에서 공통적으로 사용하는 것 2. Static 변수 class Person{ static int person_count=0;//공유영역 public int age=0;//멤벼변수 public String name;//멤버변수 Person(String param_name){//생성자, 인자 this.name=param_name; person_count++; age++; } public void print_info(){ System.out.printIn("인구:" + person_count); System.out.printIn(name + ":" + age); } } public static void main(String[] args){ Person p1 = new ..

JAVA특강 / 05. 접근지정자

1. 접근지정자 개념과 종류 : 클래스내에서 멤버(멤버변수, 멤버메서드)의 접근을 제한하는 역할 - 접근지정자의 종류 분류 클래스내부 동일패키지 상속관계 모두 public o o o o protected o o o o default o o private o 2. 멤버변수 접근지정자 class Parent{ (default) String name="홍길동"; public int age = 40; protected int height = 170; private int weight = 68; } class Child extends Parent{ public static void main(String[] args){ Child c = new Child(); System.out.printIn(c.name);//홍..

JAVA특강 / 04. 메서드 오버로딩&오버라이딩

1. 오버로딩&오버라이딩 개념 - 메서드 오버로딩 : 같은 이름의 메서드를 인자만 다르게하여 작성 - 메서드 오버라이딩 : 부모클래스의 메서드를 자식클래스에서 재정의 2. 오버로딩 class Person{ String name; int age; int height; public void set_data(String p_name){ name=p_name; } public void set_data(String p_name, int p_age){ name=p_name; age=p_age; } public void set_data(String p_name, int p_age, int p_height){ name=p_name; age=p_age; height=p_height; } } public static vo..

JAVA특강 / 03. 상속

1. 상속의 개념 : 부모로부터 물려받은 속성이나 행동 2. 객체 정의 class Parent{ String name;//두개의 멤버변수 int age; public void set_name(String param_n){//두개의 메서드 name=param_n; } public void set_age(int param_i){ age=param_i; } } class Child extends Parent{//private제외하고 모두 상속 int height;//하나의 멤버변수 public void set_height(int param_h){//하나의 메서드 height=param_h; } } 3. 객체 생성 public static void main(String[] args){ Child c = new ..

JAVA특강 / 02. 생성자&예외

1. 생성자 : 어떤 일을 시작하기 전에 준비를 하는 것, 기본값을 설정함 public class Person{//객체생성 String name;//멤버변수 int age; public Person(){//생성자(인자x) this.name="사람"ㅣ this.age=1; } //Person a = new Person(); 일 때 받아옴 public Person(String name, int age){//생성자(인자o) - 인자의 유무, 갯수에 따라 여러개 생성 가능 this.name=name; this.age=age; } //Person p = new Person("이", 1); 일 때 받아옴 public void toPrint(){ System.out.printIn(this.name + "님의 나이는"..

JAVA특강 / 01. 객체&인스턴스

1. 객체지향 프로그래밍 - 객체는 사람 : 사람이 가진 속성(멤버변수)과 행덩(메서드)을 정의해 놓은 것 속성 객체 행동 홍길동 사람 걷는다 40 먹는다 눈,코,입 본다 2. 객체정의 public class Person{//객체(붕어빵틀) String name="홍길동";//멤버변수 int age=40; public void setName(String n)//메서드(행동) { name=n; } public void setAge(int i){ age=I; } } 3. 객체생성 public class Person{//객체(붕어빵틀) //객체정의 String name="홍길동";//멤버변수 int age=40; public void setName(String n)//메서드(행동) { name=n; } pub..

반응형