열거형 열거형은 이름을 갖는 정수형의 상수를 정의하여 프로그램을 이해하기 쉽게 해 준다. 열거형은 예약어 enum을 사용하여 정의한다. #include struct test { int one; }; enum test2 { ZERO = 100, ONE, TWO //기준점으로부터 1씩 증가 }; int main() { struct test a; a.one = ONE; printf("a.one = %d\n", a.one); //1 출력 printf("ONE = %d\n", ONE); //1 출력 printf("ZERO = %d\n", ZERO); //0 출력 printf("TWO = %d\n", TWO); //2 출력 return 0; } [결과] ZERO에 100이라는 수가 없다면 0으로 나온다. #include .. 더보기 상속(inheritance) 상속이란 기존클래스를 확장해서 새로운 클래스를 만드는 기술 언제 상속이 필요한가? - 기존 클래스와 유사한 클래스를 만들어야 할 경우 상속 전 소스 package kr.ac.busanit; class Car { //멤버변수 protected int speed; protected String color; //private는 복사가 안된다. //생성자 public Car() { } //멤버메소드 public void run() { System.out.println("달리다."); } public int getSpeed() { return speed; } public void setSpeed(int speed) { this.speed = speed; } public String getColor() { retu.. 더보기 객체와 클래스(2) 객체를 어떻게 표현할 것인가? - 객체를 생성하는 틀로 사용되는 클래스 - 개념적인 클래스와 자바의 클래스 AccountTest.java package kr.ac.busanit; public class AccountTest { public static void main(String[] args) { // TODO Auto-generated method stub Account myAccount = new Account("111-1111-1111"); myAccount.deposit(1000000); System.out.println("통장잔액은: " + myAccount.getBalence()); myAccount.withdraw(100000); System.out.println("통장잔액은: " + my.. 더보기 이전 1 ··· 14 15 16 17 18 19 20 ··· 98 다음 목록 더보기