재귀함수 이용 import java.util.Scanner; public class FiboTest { public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.println("피보나치 위치 입력 : ");Scanner scan = new Scanner(System.in);long n = scan.nextInt();System.out.println("fibo[" + n + "] = " + fibo(n));} static long fibo(long n) {// TODO Auto-generated method stubif (n == 1 || n == 2)return 1;elsereturn fibo(n - 1) + ..
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..
- Total
- Today
- Yesterday
- 정보
- SQL
- db
- 파이썬
- ERP
- 메모장
- 안드로이드
- 졸업작품
- 충북대
- 오라클
- 도전과제
- 청주
- 잡담
- 이론
- 배열
- jsp
- 게임
- 프로젝트
- SVN
- 자바
- JQuery
- CSS
- 자바스크립트
- 클래스
- 데이터베이스
- 아두이노
- HTML
- 알고리즘
- 정렬
- 소켓
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |