일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- Effective JAVA
- 접근지시자
- 프리미티브 타입
- 브릿지 메소드
- auto.create.topics.enable
- 함수형 인터페이스
- annotation processor
- 바운디드 타입
- 정렬
- 자바할래
- 람다식
- System.err
- Java
- System.in
- 항해99
- Switch Expressions
- junit 5
- 합병 정렬
- 제네릭 타입
- System.out
- github api
- Study Halle
- 상속
- 제네릭 와일드 카드
- public 필드
- 스파르타코딩클럽
- 로컬 클래스
- raw 타입
- 익명 클래스
- 자바스터디
- Today
- Total
목록전체 글 (271)
코딩하는 털보
객체 지향 프로그래밍 27. 상속에서 클래스 생성 과정과 형변환 하위 클래스 생성시 항상 상위 클래스가 먼저 생성되어야 한다. package inheritance; public class VIPCustomer extends Customer{ //상위 클래스(Customer) 지정 double salesRatio; private int agentID; public VIPCustomer() { //super(); //아무런 상위 클래스 생성자 호출 명령이 없으면 pre-compile 단계에서 이 함수가 들어감 //super : 상위 클래스의 메모리 위치 함수, super() : 상위 클래스의 기본 생성자 호출 //super(0, null); //만약 상위 클래스의 기본 생성자가 없으면, 명시적으로 상위 클래..
객체 지향 프로그래밍 25. 상속이란 클래스에서 상속의 의미 : 새로운 클래스를 정의할 때 이미 구현된 클래스를 상속받아서 속성이나 기능이 확장되는 클래스를 구현 함. class B extends A { } 상속하는 클래스 : 상위 클래스 상속받는 클래스 : 하위 클래스 자바에서는 다중 상속이 불가능하다. 상속을 사용하는 경우 : 상위클래스는 더 일반적인 개념과 기능을 가짐 하위클래스는 더 구체적인 개념과 기능을 가짐 상위 클래스 package inheritance; public class Customer { protected int customerID; // 하위 클래스들이 참조할수 있도록 private가 아닌 protected 사용 protected String customerName; protect..
객체 지향 프로그래밍 22. ArrayList 사용하기 ArrayList 자바에서 제공하는 객체 배열이 구현된 클래스 객체 배열을 사용하는데 필요한 여러 메서드들이 구현되어 있음 package array; import java.util.ArrayList; public class ArrayListTest { public static void main(String[] args) { //ArrayList list = new ArrayList(); //요소 자료형 미지정 ArrayList list = new ArrayList(); //요소 자료형 지정 //몇가지 메서드 가능 테스트 list.add("aaa"); //add 메서드를 통해 요소 추가 list.add("bbb"); list.add("ccc"); fo..
객체 지향 프로그래밍 21. 다차원 배열 다차원 배열 2차원 이상의 배열 2차원 배열 int[][] arr = new int [2][3]; //6개 요소 package array; public class TwoDimension { public static void main(String[] args) { //int[][] arr = new int[2][3]; int[][] arr = {{1,2,3},{4,5,6,7}}; System.out.println(arr.length); //2차원 배열에서 length는 행의 개수 System.out.println(arr[0].length); //0번째 행의 길이 System.out.println(arr[1].length); //행을 기준으로 열을 돌린다.(2중 fo..
객체 지향 프로그래밍 19. 객체 배열 객체 배열 (참조 자료형 배열) Book[] library = new Book[5]; //null이 초기화됨 //실제로는 객체의 주소가 들어가게 된다 배열로 만 클래스 생성 package array; public class Book { private String title; private String author; public Book() { } public Book(String title, String author) { this.title = title; this.author = author; } public String getTitle() { return title; } public void setTitle(String title) { this.title = t..
객체 지향 프로그래밍 17. 배열 배열이란 동일한 자료형의 순차적 자료 구조 ex) 학생 100명에 대한 학번 변수 배열 선언 int[] arr = new int[10]; //int 10개 = 40byte length=10, 0~9 int arr[] = new int[10]; 배열은 fixed length이기 때문에 만약 배열의 길이를 늘리고 싶다면, 더 긴 배열을 선언한 뒤 값을 복사해야 한다. 배열은 연속적이어야 한다. (중간에 비어있으면 안된다.) 데이터가 들어가거나 빠질때 추가적인 작업이 필요하다. 배열을 사용하는 가장 큰 이유 : 인덱스 연산자 arr[4] //추출이 편하고 속도가 빠름 ArrayList를 쓰면 편하게 배열을 사용할 수 있다. package array; public class A..
객체 지향 프로그래밍 15. static 응용 singleton pattern 단 하나만 존재하는 인스턴스 (ex 학교 객체) 생성자는 private로 생성 클래스 내에서 static으로 유일한 객체 생성 외부에서 유일한 객체를 참조할 수 있는 public static get() 메서드 구현 package staticex; public class Company { private static Company instance = new Company(); //내부적으로 인스턴스 생성 private Company() { //생성자 private로 생성 } public static Company getInstance() { //외부에서 인스턴스 생성과 무관하게 사용하기 위해 static으로 생성 if (insta..
객체 지향 프로그래밍 14. static 변수, 메서드 여러 인스턴스가 같은 변수 및 메서드를 공유해야할 필요가 있을때 static 변수 private static int serialNum = 1000; 처음 프로그램이 로드될 때 데이터 영역에 생성됨 클래스 이름으로 참조 Student.serialNum = 100; static 메서드 static 변수를 위한 기능을 제공하는 메서드 인스턴스 변수를 사용할 수 없음 public static int getSerialNum() { //static 메서드 int i = 0; // 지역변수 사용가능 //studentName = "Lee"; //인스턴스 변수 사용할 수 없음 return serialNum; } 클래스 이름으로 참조 System.out.println..
객체 지향 프로그래밍 12. 객체 간 협력 객체 지향 프로그램은 객체를 정의 하고 객체 간의 '협력'을 구현한 프로그램 학생, 버스, 지하철 객체 간 협력 프로그램 학생 package cooperation; public class Student { String studentName; int grade; int money; public Student(String studentName,int money) { this.studentName = studentName; this.money = money; } public void takeBus(Bus bus) { //버스 객체와의 협업 bus.take(1000); this.money -= 1000; } public void takeSubway(Subway subw..
객체 지향 프로그래밍 11. this에 대하여 this의 역할 자신의 메모리를 가리킴 public static void main(String[] args) { BirthDay day = new BirthDay(); day.setYear(2000); //setYear 메서드에 this가 있을때 생성된 인스턴스(day)의 메모리 } 생성자에서 다른 생성자를 호출 함 public Person() { //age = 10; //this로 다른 생성자를 호출할때 그위에 다른 statement는 올 수 없다. this("이름 없음",1); //아래의 생성자 호출하여 변수 초기화 } public Person(String name,int age) { this.name = name; this.age = age; } 인스턴..