본문 바로가기
비트 장기/JAVA

7/13 배움(클래스 복습떄 용어정리하기)

by woohyun22 2018. 7. 13.

//alt + shift + r 같은 문자 다바뀜 핵좋음


용어 확실히 정리하기 

명제에대한 정의를 말해줘야한다.

면접에서 자신감을 가지고 대답(기술용어를 정리)연관시켜서 말하는게 좋다. 

class말고는 질문할게없다.한줄정리하기 뉴스 시사 상식 대비 4차 산업혁명


스캐너, 배열 등 기본 많이 쓰이는것들은 따로 정리 추가해나가기

단축키 정리도


클래스는 생성자 속성 메소드로 나뉜다.


상속개념 


매개변수 = 선물들고갈때 받는사람 인수 전달을 하는데 받는 변수


오버로딩은 이름 중복이 가능하다.


오버라이딩과 구분하자

a(객체) = new;

오래가지 못하는것.


public 공공의

private 개인적인


리턴값 돌아올때 가져오는것 

this() 나의 것으로 쓸때

opp 객체 지향 c++


ex) 비행기 설계도 = class

     비행기 = 객체 = object


설계도를 가지고 객체를 만드는 명령이 new


         비행기 이름

String    s   =   new

설계도            만들어라


f16   =  new 비행기();

객체


int a; = 변수

String b = 객체= object


다형성 = 여러가지 상황이 일어날수 있는 상황 

프로그램은 이미 작성됬는데 실제로 사건이 일어나야 상황을 알수있는것

지갑은 떨어져있는데 어떤 상황이 일어날지 모른다.


클래스,사과


속성(명사) : 변수명 칼라 = 필드

색깔 무게 당도 원산지 등


동작(동사) : 함수 = 메소드


클래스 1번


package pack2;

//class위 import 밑

//클래스는 여기에 작성

class Airplane{

//클래스 이름은 첫자를 대문자로 하자

int price;

int color;

int national;//속성을 정의한다

}


public class asdf {

public static void main(String[] args) {

Airplane f16 = new Airplane();

f16.color = 10;

f16.price = 20;

f16.national = 30;

System.out.println(f16.color);

System.out.println(f16.price);

System.out.println(f16.national);

}

}

//1 위에 만든 class는 Airplane class이다.

//2 class를 이용하여 객체를 생성시킬때 new를 이용한다.

//3 현재 f16을 객체(object)라고 한다.

//4 class안의 변수들은 모두 Airplane의 속성이다.



클래스를 쓰는경우


클래스2번

package pack2;

class Fruit{

int color,price,orignal,weight;

}

public class asdf {

public static void main(String[] args) {

//이렇게 사용하는것은 객체지향이 아닌모습

int BananaColor, BananaPrice, BananaOrignal, Bananaweight;

int AppleColor , ApplePrice, AppleOrignal, Appleweight;

int OrangeColor , OrangePrice, OrangeOrignal, Orangeweight;

int MangoColor , MangoPrice, MangoOrignal, Mangoweight;

int WatermelonColor , MWatermelonPrice, WatermelonOrignal, Watermelonweight;

Fruit kiwi = new Fruit();//()꼭 넣기

int color;

int price;

int orignal;

int weight;

//객체지향 프로그램적인 모습

Fruit Banana = new Fruit();

Fruit Apple = new Fruit();

Fruit Orange = new Fruit();

Fruit Mango = new Fruit();

Fruit Watermelon = new Fruit();

//이럴때 클래스를 쓴다.

}

}



여행갈준비다하고 짐 다싼거 = 캡슐화 -> 종합감기약


클래스 3번


값 초기화 default나오는거 보여주기


package pack2;

class Apple{

int a;

int b = 10;

int c;

//class 안에 있는 변수는 field라 부른다.

//a,b,c는 Apple의 member다

}

public class asdf {

public static void main(String[] args) {

Apple t1 = new Apple();//비행기 한대 만들어짐

//System.out.println(Apple.a); 비행기 설계도를 타려고함

System.out.println(t1.a+" "+t1.b+" "+t1.c);

//객체는 생성될때 안에들어가있는 초기값을 0으로 잡아준다.

Apple t2 = new Apple();//비행기 두대 만들어짐

System.out.println(t2.a+" "+t2.b+" "+t2.c);

//두 비행기는 아예 다른거다

t1.a = 100;//t1.b = 0이 나온다.

System.out.println(t1.a);

System.out.println(t2.b);

}

}


클래스 안의 클래스와 동일한 이름이 있을경우 실행순서


4번


package pack2;

class Apple{//객체가 생성될때 무조건 class를 먼저 한번 실행한다.

int a;

int b;

int c;

//생성자는 변수를 한번 초기화하기 위해 필요

Apple(){//이 구조를 생성자라고 한다. feat)주민센터

//객체는 생성될때 반드시 생성자를 다녀온다.

//생성자이름은 반드시 class와 이름이 같아야한다.

//변수를 한번 초기화 하기 위해서 생성자 필요

System.out.println("호랑이");

System.out.println("코끼리");

a=10;

b=20;

c=30;

}

}


5번


public class asdf {

public static void main(String[] args) {

System.out.println("앵무새1");

Apple t1 = new Apple();//여기서 객체가 생성된다. 객체이름은 t1

System.out.println("앵무새2");

//new를 만나면 class에서 먼저 실행된다.

//class안에서 자신과 같은 코드가 있으면 먼저 실행을 해본다.

//그러므로 호랑이 코끼리가 나오게되는것

Apple t2 = new Apple();

Apple t3 = new Apple();

System.out.println("앵무새3");//몇번 나오든 다시 class로 올라갔다가 온다.

System.out.println(t1.a+" "+t1.b + " " +t1.c);

System.out.println(t2.a+" "+t2.b + " " +t2.c);

System.out.println(t3.a+" "+t3.b + " " +t3.c);

}

}


함수 call하는법 실행순서 


6번


package pack2;

//class만들라고 하면 이 형태로 만들

//alt shift r 같은 문자 다바뀜 핵좋음

class Robot{

int a,b,c;

Robot(){

System.out.println("생성자 call");

}

void 수현() {//이게 함수를 만드는것 이 함수의이름은 수현

//함수는 class안에서 

System.out.println("네");

System.out.println("왜요?");

}

void 관우() {//이런 함수는 무한대로 만들수있다.

System.out.println("아주 잘생겼다.");

}

void move() {

System.out.println("걸어갑니다.");

}

}


public class asdf {

public static void main(String[] args) {

Robot t1 = new Robot();

t1.수현();//이것이 함수를 call한다는것

t1.수현();//함수 내용 불러오기

for (int i = 0; i < 5; i++) {

t1.수현();//call 하면 함수를 불러와서 함수의 내용이 실행되는거임

}

t1.관우();

System.out.println("앵무새1");

t1.move();//함수를 부를떄 ()를 빼는 실수 x

System.out.println("앵무새2");

}

}





package pack2;
//class만들라고 하면 이 형태로 만들
//alt shift r 같은 문자 다바뀜 핵좋음
class Bird{
int a,b,c;
Bird(){
System.out.println("call");
}
void Fly(){
System.out.println("새가 날아간다");
}
}
public class asdf {
public static void main(String[] args) {
Bird t1 = new Bird();
t1.Fly();
}
}

728x90

'비트 장기 > JAVA' 카테고리의 다른 글

7/15까지 문제 한번 풀어보기  (0) 2018.07.16
7/13 복습  (0) 2018.07.15
7/12 복습  (0) 2018.07.13
7/12 배움 (switch문,while문, )  (0) 2018.07.12
7/11 비트컴퓨터 자바 복습 과제  (0) 2018.07.11

댓글