목록java (69)
June is Combung
package test; //상속 // 부모 클래스 --> 만드는 이유 : 여러가지 클래스를 만들때 중복되는 기능들과 변수를 따로 빼서 // 클래스를 좀더 단순하고 전문적으로 설계하기 위해서 //상속 3가지 // 일반 클래스를 상속받는다 : 부모클래스도 객체 생성가능 자식클래스도 객체생성 가능 // 추상 클래스를 상속받는다 : 부모클래스는 객체 생성 불가능 , 자식만 생성가능 // 인터페이스를 상속받는다 : 부모클래스는 단 한개밖에 없다 .. 그래서 나온게 인터페이스다 : 여러개 상속을 하기위해서 // 인터페이스는 클래스가 아니다 --> 인터페이스는 객체를 만들 수가 없다 // 추상클래스보다 더 추상적인 애 : 무조건 모든 메서드가 다 추상메서드 , 변수는 상수만 가능하다 // 다 추상메서드이기때문에 인..
package test; //접근 제어자 종류 : default , public, private , protected class A_ { int a = 100; // 다른 클래스에서도 접근이 가능하다 protected int b = 200; private int c = 300; // 메서드 오버로딩 A_() { } public A_(int a, int b, int c) { super(); // 부모의 생성자 object : this.a = a; // 인스턴스 객체의 주소값이 this this.b = b; this.c = c; } void print() { System.out.println("A클래스야 "); System.out.printf("a=%d b=%d c=%d \n", a, b, c); } pri..
package test; // 자식은 여러명일 수 있다 , 부모는 단 한명 // extends 부모 클래스를 지정하는데 // extends 는 단 한개의 부모클래스만 들수 있다 /* 같은 클래스 내에서 같은 이름 부모 - 자식클래스 사이에서 메서드 오버 로딩 vs 메서드 오버롸이딩 (덮어쓰기 ) 메서드는 같은 이름 생성하는데 부모클래스에 있는 메서드를 매개 변수값을 다른 타입, 갯수 변화를 같은 이름 같은 매개변수 : 완전 일치한 메서드 줘서 같은 이름으로 호출 자식 클래스에서 내용만 바꿔치기 */ // 자바안에 모든 것들의 조상은 object // b의 부모클래스 , 상위클래스 class A { int a = 100; int b = 200; int c = 300; // 메서드 오버로딩 A() { } p..
package test; //직접적으로 값 수정 --> 변수 = 값 : 대입연산자 //간접적으로 값 수정 --> 메서드를 사용하는것 : 외부에서 값을 주는 매개 인자값으로 매개변수를 통해서 인스턴스변수에 접근이 가능하다 class Person { String name; String brithday; String nationality; String job; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getBrithday() { return brithday; } public void setBrithday(String brithday) { this.brith..
package test; import java.util.Random; class Unit { Random rd = new Random(); final int MAX_HP; // 상수는 무조건 대문자 int hp; String name; Unit(int hp, String name) { MAX_HP = hp; this.hp = hp; this.name = name; } void attack(Unit unit, int range1, int range2) { int attackhp = rd.nextInt((range2 - range1) + 1) + range1; unit.hp = unit.hp - attackhp; System.out.printf("%s가 %s %d 공격 (%d / %d) \n", name, ..
package week5; import java.util.Date; import java.text.SimpleDateFormat; public class Day19_1 { public static void main(String[] args) { Date date = new Date(); System.out.println(date); // Fri Jan 29 15:13:12 KST 2021 new 해서 객체를 만들때 시간이다 // 2021년 1월 29일 // yyyy -> 년 데이트를 받아올꺼야 // MM -> 월 데이터 // MMM -> jan 영어 월데이터 // dd -> 일데이더 // E -> 요일데이터 // hh -> 시 데이터 // HH 24시간 형태 hh 12시 형태 // mm -> 분 데이터 ..
package week5; import java.util.ArrayList; class Book { int b_no; String b_name; String r_Date; int id; public Book(int b_no, String b_name, String r_Date, int id) { super(); this.b_no = b_no; this.b_name = b_name; this.r_Date = r_Date; this.id = id; } } class User { int id; int b_no; int r_day; public User(int id, int b_no, int r_day) { super(); this.id = id; this.b_no = b_no; this.r_day = r_da..
package week5; import java.util.ArrayList; import java.util.Arrays; public class Day18_3 { public static void main(String[] args) { // 0 1 int arr[] = { 10, 20 }; // new int[2] // arr[2] = 50; 오류가 난다 // 배열 한번 길이가 정해지면 수정이 불가능하다 System.out.println("==="); System.out.println(Arrays.toString(arr)); int size = arr.length; int temp[] = arr; arr = new int[size + 1]; for (int i = 0; i < size; i++) { ar..