1 / 11

자바 10일 작전

자바 10일 작전. 제 3 일 객체와 클래스. 한국교원대학교 정영식. 객체의 생성과 파기. 생성자 StringBuffer sb=new StringBuffer(); 파괴자 별도의 파괴자는 없다. Garbage Cllection 에 의해 자동 파괴된다. finalize() 는 종료 대기 → OS 가 처리 GC 강제 호출 : Runtime.gc(). 클래스. 클래스 선언 모든 클래스는 한 개씩의 상속만을 지원한다(?). 다중 상속을 하고자 할 경우 인터페이스를 상속받는다.

Download Presentation

자바 10일 작전

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 자바 10일 작전 제 3 일 객체와 클래스 한국교원대학교 정영식

  2. 객체의 생성과 파기 • 생성자 StringBuffer sb=new StringBuffer(); • 파괴자 • 별도의 파괴자는 없다. • Garbage Cllection에 의해 자동 파괴된다. • finalize()는 종료 대기 → OS가 처리 • GC 강제 호출 : Runtime.gc()

  3. 클래스 • 클래스 선언 • 모든 클래스는 한 개씩의 상속만을 지원한다(?). • 다중 상속을 하고자 할 경우 인터페이스를 상속받는다. • 모든 클래스는 Object를 상속한다. • 클래스 정의 [keywords] class MyClass [extends Superclass] [implements Interface]{ 멤버 변수, 자동 변수, 생성자, 멤버 메소드, 정적 멤버 변수, 정적 멤버 메소드 }

  4. 애플리케이션 클래스 public class MyClass { public static voidmain(String args[]) { } } • public : 외부 프로그램에서 호출 • static : 서브 클래스에서 수정할 수 없도록 • void : 리턴값 없음 • main : 반드시 필요한 메소드

  5. 애플릿 클래스 import java.awt.*; import java.applet.*; public class MyClass extends Applet(){ public void init(){} public void start(){} public void repaint(){} public void paint(Graphics g){} public void stop(){} public void destory(){} }

  6. 사전 정의된 인스턴스(1) • null String name=null; • name이라는 String 객체가 null로 초기화됨 • 기본 값이 아닌 객체를 초기화할 때만 사용한다. • this this.name=“nurunso”; • 객체의 현재 인스턴스를 가리킨다. • super super.name=“jys”; • 상위 클래스의 인스턴스를 가리킨다.

  7. 사전 정의된 인스턴스(2) class Child extends Parent { String strC="c"; public static void main(String[] args) { Child c=new Child(); } Child() { System.out.println("child"); System.out.println(this.strC); System.out.println(super.strP); } } class Parent { String strP="p"; Parent() { System.out.println("parent"); } } 출력 결과 parent child c p

  8. 클래스 수식어(1) • public • public이 아니면 import한 클래스에서 사용 불가 • abstract • 직접적인 인스턴스 생성 불가 Number n=new Number(1); //가능 Number n=new Integer(1); //불가 • 클래스 계층 구조를 만들기 위해 사용 • 코드 없는 메소드(abstract)와 함께 공존

  9. 클래스 수식어(2) • final • 더 이상 확장될 수 없으므로 완벽히 구현 • String, Integer, Long, Float, Double 등 • abstract한 final 메소드는 당연 불가 • 컴파일러는 인라인 코드로 생성 • 일종의 계약(사용 제한), 보안 : 각종 DB 관련... • strictfp • 소수 타입을 정확하게계산

  10. 변수 수식어 • final • static과 마찬가지로 자식 클래스에서 변경 불가 • transient(일시적인) • 객체 지속적으로 저장되지 않는다. • 게좌번호와 같이 예민한 자료가 JVM 외부의 스트림에 저장되는 것을 막는다. • volatile(휘발성) • 다중 프로세서 환경에서 비동기적으로 수정 가능

  11. 접근 제한자

More Related