분류 전체보기 176

예외 처리

예외 클래스들 -모든 예외 클래스의 최상위 클래스는 Exception 클래스 -자바에서는 다양한 예외들에 대해 그 처리를 위한 클래스를 제공한다. -Arithmetic Exception: 정수를 0으로 나눈 경우 발생 -NullPointerException: 초기화 되지 않은 Object를 사용하는 경우 Dog d = null; System.out.println(dog); -ArrayIndexOutOfBoundsException: 배열의 크기를 넘어선 위치를 참조하는 경우 -FileNotFoundException: 참조하는 파일이 지정된 위치에 존재하지 않는 경우 -ClassNotFoundException: 클래스가 로드되지 않은 경우 -InterruptedException: Thread.sleep(),..

+24 라이브러리

Sawon 객체 생성!! 사원의 이름은 김입니다. name = 김 Sawon 객체 메모리 해제 class Sawon { String name; // null public Sawon(String name) // 초기화 { this.name = name; System.out.println("Sawon 객체 생성!!"); } public void display() { System.out.println("name = " + name); } @Override public String toString() { return "사원의 이름은 " + name + "입니다."; } @Override protected void finalize() throws Throwable { System.out.println("Sawon..

수업 2022.06.07

+24 예외처리(throw, throws, finally)

throw -많이 사용하지 않음(테스트 용) -임의로 발생 throw new 예외처리 생성자() -다음 줄에는 코딩 할 수 없음 (예: throw new Exception()) throws -예외 선언하기 > 라이브러리에서 사용 -예외에 대한 예측이 가능(어떤 에러가 발생할 지 알고 코딩) -메서드 내에서 예외처리를 하지 않아도 됨 예외처리의 단점 -소스코딩, 복잡한 소스 방지 -복구 할 수 없음(시스템에 의해 처리 됨) 사용법 -메서드 뒤에 붙인다. public void display() throws 예외처리 종류 -여러 개 선언 할 수 있음 public void disp() throws Exception, SQLException... finally -필요시에만 사용(서버, 파일, 데이터베이스) -tr..

수업 2022.06.07

인터페이스

인터페이스란? -모든 메서드가 추상 메서드로 선언 됨 public abstract -모든 변수는 상수로 선언 됨 public static final interface 인터페이스이름 { public static final float pi = 3.14F; public void makeSth(); } 인터페이스 정의와 구현 10+0=10 10-0=10 10*0=0 10/0=-99999999 public interface Calc { double PI = 3.14; int ERROR = -99999999; int add(int num1, int num2); int substract(int num1, int num2); int times(int num1, int num2); int divide(int num1, ..

추상 클래스

추상 클래스 구현하기 -메서드에 구현 코드가 없으면 abstract로 선언 -abstract로 선언된 메서드를 가진 클래스는 abstract로 선언 -모든 메서드가 구현 된 클래스라도 abstract로 선언되면 추상 클래스로 인스턴스화 할 수 없음 -추상 클래스에서 추상 메서드는 하위 클래스가 상속해서 구현 -추상 클래스 내의 추상 메서드 : 하위 클래스가 구현해야 하는 메서드 -추상 클래스 내의 구현 된 메서드 : 하위 클래스가 공통으로 사용하는 메서드 (필요에 따라 하위 클래스에 재정의 함) Desktop display Desktop typing Desktop turnOff public class ComputerTest { public static void main(String[] args) { Co..