본문 바로가기
국비교육/JAVA

국비교육 8일차

by Diligejy 2018. 12. 5.

1. 클래스 구현 : 속성 + 메소드

접근제한자 class User_Name{
멤버; // 멤버변수, 상수/ 생성자, getter & setter, 기능형 메소드}


java beans : class 중에 setter & getter


2. jar로 만들어서 참조형 구현을 할 수 있다.


3.

toString() : java.lang.Object = 객체의 주소를 동적으로 할당된 16진수 값으로 리턴하는 메소드


4.

@Override

public String toString() {

return null;

}


5. 

멤버 변수를 출력할 때 println을 쓰면 콘솔에서밖에 못 씀 하지만 toString을 활용하면 콘솔이 아니라 웹에서도 쓸 수 있음


6.


package com.test;

// 두 수를 사칙연산하는 클래스 


public class Calc {

private int a;

private int b;

public Calc() {

super();

}

public Calc(int a, int b) {

super();

this.a = a;

this.b = b;

}

public int getA() {

return a;

}

public void setA(int a) {

this.a = a;

}

public int getB() {

return b;

}

public void setB(int b) {

this.b = b;

}

public int getHap() {

return a + b;

}

public int getSub() {

return a - b;

}

public int getMul() {

return a * b;

}

public int getDiv() {

return a / b ;

}

public String toString(){

String str01 = String.format("%5d + %5d = %5d\n", a, b, this.getHap());

String str02 = String.format("%5d + %5d = %5d\n", a, b, this.getSub()); 

String str03 = String.format("%5d + %5d = %5d\n", a, b, this.getMul());

String str04 = String.format("%5d + %5d = %5d\n", a, b, this.getDiv());

return str01+str02+str03+str04;

}

public static void main(String[] args) {

Calc c1 = new Calc(200, 100);

System.out.println(c1);

}

}


#7

s1.getAddress().setAddr("서울");


#8

남의 클래스를 활용할거면 생성자를 보고, static인지 nonstatic인지를 봐라

'국비교육 > JAVA' 카테고리의 다른 글

12월 7일 국비교육 10일차  (0) 2018.12.07
국비교육 9일차  (0) 2018.12.06
12월 4일 국비교육 7일차  (0) 2018.12.04
12월 3일 국비교육 6일차  (1) 2018.12.03
11월 30일 국비교육 5일차  (0) 2018.11.30

댓글