자바 프로그래밍22 상속C 추상 메소드와 추상 클래스 선언되어 있지만 구현되지 않은 메소드, abstract로 선언 public abstract String getName(); public abstract void setName(String s); 2가지 종류의 추상 클래스 사례 추상 메소드를 하나라도 가진 클래스 클래스 앞에 반드시 abstract라고 선언해야 한다. 추상 메소드를 포함하는 추상 클래스 abstract class Shape { public Shape() { public void paint() { draw();} abstract public void draw(); } 추상 메소드가 하나도 없지만 abstract로 선언된 클래스 추상 메소드가 없는 추상 클래스 abstract class MyComponent { St.. 2023. 6. 12. EmployeeTest.java class Employee { private String name; private String id; static private int count = 0; public Employee(String name, String id) { this.name = name; this.id = id; count++; } public double earnings() { return 0; } public String toString() { return name + "(" + id + ")"; } public static int getCount() { return count; } } class SalariedEmployee extends Employee { private double monthlySalary; public .. 2023. 6. 9. DateTest class Date { private int month; private int day; private int year; public Date(int month, int day, int year) { this.month = checkMonth(month); this.year = year; this.day = checkDay(day); } private int checkMonth(int testMonth) { if (testMonth >= 1 && testMonth 0 && testDay daysPerMonth[month]) { day = 1; month++; if (month > 12) { month = 1; year++; } if (month == 2 && day == 29 && (year % 400 =.. 2023. 6. 8. 9-weeks BankAccount import java.util.Scanner; public class BankAccount{ private double balance; public BankAccount(double initialBalance){ if(initialBalance > 0.0) balance = initialBalance; } public void credit(double amount){ balance += amount; } public double getBalance(){ return balance; } public static void main(String[] args){ BankAccount account1 = new BankAccount(50.00); BankAccount account2 = ne.. 2023. 6. 7. 이전 1 2 3 4 ··· 6 다음