class Vehicle {int speed; void drive() {};void stop() {};} public class AirPlane extends Vehicle {int height; void takeOff() {};void landing() {}; public static void main(String arg[]) {AirPlane ap1 = new Vehicle(); //에러 부모 -> 자식간 인스턴스 할당 불가, 형변환 생략불가AirPlane ap2 = (AirPlane) new Vehicle(); // 강제 형변환 Vehicle v1 = new AirPlane(); //정상적인 코드, 형변환 생략가능Vehicle v2 = (Vehicle) new AirPlane(); // 강제 형변환..
과목 : 자바 클래스 기본, 인터페이스, 상속, 다중상속
package afternoon; public class Factorial { static int num = 5;public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.println("factorial "+num+" = "+factorial(num));} private static long factorial(int i) {// TODO Auto-generated method stubif(i==1)return 1;elsereturn i * factorial(i-1);}}
클래스 변수는 해당 클래스가 공통으로 사용하는 변수를 말하며 인스턴스 변수에 static 예약어를 사용한다. //클래스 변수를 이용한 제목을 지정하지 않은 문서의 번호 매기기package afternoon; public class DocumentTest { public static void main(String[] args) {// TODO Auto-generated method stubDocument dc = new Document();Document dd = new Document("Class Define");Document de = new Document();Document df = new Document("Serial Test");Document dg = new Document();Document..
일반상속과는 다르게 인터페이스는 다중상속이 허용된다 package afternoon; public class InterfaceInheritance { public static void main(String arg[]){C obj = new C();obj.method1();obj.method2();obj.method3();obj.method4();}}interface C1{void method1();void method2();}interface C2{void method3();}interface C3 extends C1,C2{void method4();}class C implements C3{ @Overridepublic void method1() {// TODO Auto-generated method s..
public class TestCar { public static void main(String[] args) {// TODO Auto-generated method stub Car car1 = new Car("white", "auto", 4); // 생성자로 인자 전달Car car2 = new Car(car1); // 생성자를 이용한 값 복사Car car3 = car2; // 보오오옥사 // car2와 3은 동일한 객체(깊은 복사, 주소까지 복사한 것)car2.color = "black";car3.trans = "stick"; // car1은 2와 3과 다른 객체(얕은 복사)car1.door = 3; System.out.println("car1 : " + car1.color + ", " + car1.d..
/*static method로 구현했기 때문에 * 객체가 할당되지 않아도(기본적인 객체가 자동할당됨) 메소드를 사용할 수 있다. * min -> first -> second 순서로 호출 * 스택이기 때문에 종료는 반대로 진행됨*/public class CallStack { public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.println("1 start");firstMethod();System.out.println("1 end");} static void firstMethod() {// TODO Auto-generated method stubSystem.out.println("2 start");Second..
- Total
- Today
- Yesterday
- 도전과제
- 아두이노
- 알고리즘
- 배열
- HTML
- 자바스크립트
- CSS
- 청주
- 프로젝트
- 파이썬
- 데이터베이스
- 졸업작품
- 메모장
- JQuery
- 정보
- 자바
- 정렬
- db
- 게임
- 이론
- SQL
- 안드로이드
- 클래스
- jsp
- ERP
- 충북대
- 소켓
- SVN
- 오라클
- 잡담
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |