/*
class SharpPencil {
private int width;
private int amount;
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
}
class BallPen extends SharpPencil {
String color;
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
class FountainPen extends BallPen {
public void refill(int n) {
setAmount(n);
}
}
class Person{
private int age;
private String name;
public Person() {
System.out.println("Person의 기본 생성자");
}
public Person(int age) {
this.age=age;
System.out.println("Person의 나이 생성자");
}
int getAge() {
return age;
}
}
class Student extends Person{
public Student() {
System.out.println("Student의 기본 생성자");
}
public Student(int a) {
System.out.println("Student의 나이 생성자");
}
}
class Main{
public static void main(String[] args) {
Student s = new Student(10);
System.out.println(s.getAge());
}
}
/*
class Point{
private int x,y;
public Point() {
this.x=this.y=0;
}
public Point(int x,int y)
{
this.x=x;
this.y=y;
}
public void show() {
System.out.println("("+x+","+y+")");
}
}
class ColorPoint extends Point{
private String color;
public ColorPoint(int x,int y,String color) {
super(x,y);
this.color=color;
}
public void show() { // 부모클래스의 메소드를덮어씌우기 overriding
super.show();
System.out.println(color);
}
// public void showColorPoint()
// {
// System.out.print(color);
// showPoint();
// }
}
public class Main {
public static void main(String[] args) {
ColorPoint cp=new ColorPoint(5,6,"blue");
Point p= new Point(2,3);
p.show();
cp.show();
}
}
추상클래스 abstract -
"틀"의 역할로 존재하는것 (중복되는 부분을 한번만 쓰기위해서) (그냥 슈퍼클래스로만 사용)
객체를 생성할 수 없음.
interface Animal{ //그냥 메소드도 가질수 없음, 오직 추상메소드만!
abstract void eat();
}
abstract class Person{
private int age;
private String name;
abstract void speak(); //추상메소드 (서브클래스가 무조건 오버라이딩해야함)
void sleep() {}; // 추상메소드 아님!! (그냥 내용이 없는 메소드일뿐)
}
class Student extends Person implements Animal{
public Student() {
System.out.println("Student의 기본 생성자");
}
public Student(int a) {
System.out.println("Student의 나이 생성자");
}
@Override
void speak() { //이 메소드는 꼭 작성해야함 -> Person의 추상메소드이기 때문에
}
@Override
public void eat() {
// TODO Auto-generated method stub
}
}
class Main{
public static void main(String[] args) {
Student s = new Student(10);
}
}
*/
class TV{
private int size;
public TV(int size) {this.size=size;}
protected int getSize() {return size;}
}
class ColorTV extends TV
{
int color;
public ColorTV(int size ,int color)
{
super(size);
this.color=color;
}
public void printProperty()
{
System.out.print(getSize()+"인치 "+color+"컬러");
}
}
+
class Main{
public static void main(String[] args) {
ColorTV myTV=new ColorTV(32,1024);
myTV.printProperty();
}
}