練習問題

This commit is contained in:
2026-10-29 16:04:28 +09:00
parent d9529e2971
commit 43f53da2f2
136 changed files with 1721 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
public class Animal {
private String name;
public void print() {
System.out.println(this.name + "は走りました。");
System.out.println(this.name + "は食事をしました。");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@@ -0,0 +1,4 @@
public class Cat extends Animal {
}

View File

@@ -0,0 +1,9 @@
public class Dog extends Animal{
public void print() {
System.out.println(this.getName() + "は走りました。");
System.out.println(this.getName() + "ドッグフードを食べました。");
}
}

View File

@@ -0,0 +1,12 @@
public class Q13_1 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Cat cat = new Cat();
cat.setName("タマ");
cat.print();
}
}

View File

@@ -0,0 +1,9 @@
public class Q13_2 {
public static void main(String[] args) {
Dog dog = new Dog();
dog.setName("ポチ");
dog.print();
}
}