Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
オブジェクト指向講座_サンプル1
import java.util.*;
class Main{
public static void main(String[] args){
Dog dogA = new Dog();
dogA.bark();
dogA.paw();
Bird birdA = new Bird();
birdA.age = 5;
System.out.println(birdA.age);
}
}
class Animal{
public int age;
public void bark(){
System.out.println("鳴く");
}
}
class Dog extends Animal{
public int hairColor;
public void paw(){
System.out.println("お手をする");
}
}
class Bird extends Animal{
public int beakColor;
public void peck(){
System.out.println("ついばむ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment