본문 바로가기

java9

JAVA 인터페이스 interface 인터페이스 - interface라는 키워드로 선언이 가능하다. - class 키워드 대신 interface 키워드가 붙는다. - 추상메서드롸 상수를 가질 수 있다. - 인터페이스를 상속 받을 시에는 implements 키워드로 상속 받는다. - 인터페이스를 상속받는 클래스는 다중 상속이 가능하다. 다중 상속을 남발하면 좋지는 않지만 대형 프로젝트에는 필요하다 package kr.or.ksmart; interface SampleInterface{ public void show(); } interface SampleInterface2{ public void print(); } class Sample implements SampleInterface, SampleInterface2{ @Override publi.. 2020. 4. 29.
JAVA - hashCode( ) hashCode 메서드 public int hashCode() Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap. The general contract of hashCode is: ◦Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used .. 2020. 4. 29.
JAVA override && final 오버라이딩 - 슈퍼클래스의 메서드와 동일한 메서드 명과 인수로 재구현 하는 방식 - 슈퍼클래스의 메서드를 재구현 할 때 @Override 어노테이션이 붙는다. package kr.or.ksmart; class Car{ private int num; private int gas; public int getNum() { return num; } public void setNum(int num) { this.num = num; } public int getGas() { return gas; } public void setGas(int gas) { this.gas = gas; } } class Bus extends Car{ @Override public void setGas(int gas) { super.set.. 2020. 4. 27.
JAVA 형 변환 1. 형변환 (캐스트) 다른 자료형(데이터형)으로 변환할 때 2. 숫자 타입 형변환 작은 숫자 타입 -> 큰 숫자 타입 : 명시적으로 형변환 package kr.or.ksmart; public class JavaBasic01 { public static void main(String[] args) { //작은 형 -> 큰 형 : 명시적으로 형변환 int inum = 160; double dnum = inum; System.out.println(inum + " - > - "+ dnum); } } 큰 숫자 타입 -> 작은 숫자 타입 : 캐스트 연산자를 활용하여 형 변환 작은 숫자 타입의 크기를 넘어서면 변환이 안된다. package kr.or.ksmart; public class JavaBasic01 { p.. 2020. 4. 21.
JAVA 클래스 1. 클래스 선언하기 - 클래스 키워드와 함께 클래스명 지정 - 접근 지정자 지정 - 필드와 함께 메서드를 갖는다. 2. 접근지정자 - public : 전 패키지 내에 접근 가능 - protected : 해당 패키지 내에서 접근 가능 - private : 해당 클래스에서 접근가능 - default : 접근 지정자가 명시 되어있지 않는 클래스나 메서드, protected와 동일 3. 필드 - 필드는 접근지정자와 데이터형 변수명으로 변수를 선언 가능 - 접근지정자 데이터형 변수명; - 필드는 주로 private으로 선언하여 캡슐화한다. **캡슐화 ; 클래스의 데이터와 기능을 하나로 묶어 구성원을 보호하는 기능 다른 패키지에서 접근할 수 없도록 보호하는 것, 데이터 은닉 4. 메서드 - 메서드는 접근지정자, .. 2020. 4. 21.
JAVA 배열 1. 배열 - 메모리 공간에 여러개의 값을 저장하는 객체 2. 배열 선언 방법 1.기본형 : 데이터형[] 변수명 = new 데이터형[배열크기]; 배열만 만드는 것 2.클래스 : 데이터형[] 변수명 = new 데이터형[]{"데이터"}; 배열을 만들때 값까지 집어넣는 것 데이터형 배열은 클래스로데이터형은 객체(클래스)로 선언가능하다. int[] numArray = new int[5]; String[] strArray = new String[5]; 3. 배열에 값 대입하기 배열의 요소를 인덱스로 접근하여 값을 대입한다. 배열의 크기를 넘어서는 인덱스로 접근하여 값을 대입할 수 없다. numArray[0] = 1; numArray[1] = 2; numArray[2] = 3; numArray[3] = 4; num.. 2020. 4. 21.
728x90
반응형