標題:
繼承 (二)
[打印本頁]
作者:
tonyh
時間:
2022-9-3 20:26
標題:
繼承 (二)
試在子類別中添加新的方法成員.
public class Ch69 {
public static void main(String[] args) {
Dog d1=new Dog("憨憨",2,1.28);
Dog d2=new Dog("球球",1,1.35);
Cat c1=new Cat("咪咪",3,0.95);
d1.showProfile();
d1.makeSound(2);
d2.showProfile();
d2.makeSound(3);
c1.showProfile();
c1.makeSound(5);
}
}
class Animal{
String name;
int age;
double weight;
Animal(String n, int a, double w)
{
name=n;
age=a;
weight=w;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,體重"+weight+"公斤.");
}
}
class Dog extends Animal
{
Dog(String n, int a, double w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1; i<=x; i++)
System.out.print("汪~");
System.out.println();
}
}
class Cat extends Animal
{
Cat(String n, int a, double w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1; i<=x; i++)
System.out.print("喵~");
System.out.println();
}
}
複製代碼
作者:
曾元瑜
時間:
2022-9-3 20:41
public class Ch01 {
public static void main(String[] args) {
Dog d1=new Dog("憨憨",2,1.28);
Dog d2=new Dog("球球",1,1.35);
Cat c1=new Cat("咪咪",3,0.95);
d1.showProfile();
d1.makeSound(2);
d2.showProfile();
d2.makeSound(3);
c1.showProfile();
c1.makeSound(5);
}
}
class Animal{
String name;
int age;
double weight;
Animal(String n,int a,double w)
{
name=n;
age=a;
weight=w;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,體重"+weight+"公斤");
}
}
class Dog extends Animal{
Dog(String n,int a,double w){
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1;i<=x;i++)
System.out.print("汪~");
System.out.println();
}
}
class Cat extends Animal{
Cat(String n,int a,double w){
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1;i<=x;i++)
System.out.print("喵~");
System.out.println();
}
}
複製代碼
作者:
余柏緯
時間:
2022-9-3 20:41
public class ch68 {
public static void main(String[] args) {
Dog d1=new Dog("憨憨",2,1.28f);
Dog d2=new Dog("球球",1,1.35f);
Cat c1=new Cat("咪咪",3,0.95f);
d1.showProfile();
d1.makeSound(2);
d2.showProfile();
d2.makeSound(3);
c1.showProfile();
c1.makesound(5);
}
}
class Animal{
String name;
int age;
float weight;
Animal(String n,int a,float w)
{
name=n;
age=a;
weight=w;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,體重"+weight+"公斤.");
}
}
class Dog extends Animal
{
Dog(String n,int a,float w)
{
super(n,a,w);
}
void makeSound(int a)
{
for(int i=1;i<=a;i++)
System.out.println("汪~");
}
}
class Cat extends Animal
{
Cat(String n,int a,float w)
{
super(n,a,w);
}
void makesound(int a)
{
for(int i=1;i<=a;i++)
System.out.println("喵~");
}
}
複製代碼
作者:
許志捷
時間:
2022-9-3 20:41
public class Ch01 {
public static void main(String[] args) {
Dog d1=new Dog("憨憨",2,1.28f);
Dog d2=new Dog("球球",1,1.35f);
Cat c1=new Cat("咪咪",3,0.95f);
d1.showProfile();
d1.makeSound(2);
d2.showProfile();
d2.makeSound(3);
c1.showProfile();
c1.makeSound(5);
}
}
class Animal{
String name;
int age;
float wgh;
Animal(String n,int a,float w)
{
name=n;
age=a;
wgh=w;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,體重"+wgh+"公斤.");
}
}
class Dog extends Animal
{
Dog(String n,int a,float w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1;i<=x;i++)
System.out.print("汪~");
System.out.println();
}
}
class Cat extends Animal
{
Cat(String n,int a,float w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1;i<=x;i++)
System.out.print("喵~");
System.out.println();
}
}
複製代碼
作者:
許洧熏
時間:
2022-9-3 20:43
public class Ch02 {
public static void main(String[] args) {
Dog d1=new Dog("憨憨",2,1.28);
Dog d2=new Dog("球球",1,1.35);
Cat c1=new Cat("咪咪",3,0.95);
d1.showProfile();
d1.makeSound(2);
d2.showProfile();
d2.makeSound(3);
c1.showProfile();
c1.makeSound(5);
}
}
class Animal{
String name;
int age;
double weight;
Animal(String n,int a,double w)
{
name=n;
age=a;
weight=w;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,體重"+weight+"公斤.");
}
}
class Dog extends Animal
{
Dog(String n,int a,double w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=0; i<x; i++)
System.out.print("汪~");
System.out.println();
}
}
class Cat extends Animal
{
Cat(String n,int a,double w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=0; i<x; i++)
System.out.print("喵~");
System.out.println();
}
}
複製代碼
作者:
吳湘儀
時間:
2022-9-3 20:43
public class Ch01{
public static void main(String[] args) {
Dog d1=new Dog("憨憨",2,1.28);
Dog d2=new Dog("球球",1,1.35);
Cat c1=new Cat("咪咪",3,0.95);
d1.showProfile();
d1.makeSound(2);
d2.showProfile();
d2.makeSound(3);
c1.showProfile();
c1.makeSound(5);
}
}
class Animal{
String name;
int age;
double weight;
Animal(String n, int a, double w)
{
name=n;
age=a;
weight=w;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,體重"+weight+"公斤.");
}
}
class Dog extends Animal
{
Dog(String n, int a, double w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1; i<=x; i++)
System.out.print("汪~");
System.out.println();
}
}
class Cat extends Animal
{
Cat(String n, int a, double w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1; i<=x; i++)
System.out.print("喵~");
System.out.println();
}
}
複製代碼
作者:
丁肇志
時間:
2022-9-3 20:44
public class Ch69 {
public static void main(String[] args) {
Dog d1 = new Dog("憨憨", 2, 1.28);
Dog d2 = new Dog("球球", 1, 1.35);
Cat c1 = new Cat("咪咪", 3, 0.95);
d1.showProfile();
d1.makeSound(2);
d2.showProfile();
d2.makeSound(3);
c1.showProfile();
c1.makeSound(5);
}
}
class Animal {
String name;
int age;
double weight;
Animal(String n, int a, double w) {
name = n;
age = a;
weight = w;
}
void showProfile() {
System.out.println(name + "今年" + age + "歲,體重" + weight + "公斤.");
}
}
class Dog extends Animal {
Dog(String n, int a, double w) {
super(n, a, w);
}
void makeSound(int x) {
for(int i = 0; i < x; i++)
System.out.print("汪~");
System.out.println();
}
}
class Cat extends Animal {
Cat(String n, int a, double w) {
super(n, a, w);
}
void makeSound(int x) {
for(int i = 0; i < x; i++)
System.out.print("喵~");
System.out.println();
}
}
複製代碼
作者:
黃子倢
時間:
2022-9-3 20:44
public class JPA01 {
public static void main(String[] args) {
Dog d1=new Dog("憨憨",2,1.28);
Dog d2=new Dog("球球",1,1.35);
Cat c1=new Cat("咪咪",3,0.95);
d1.showProfile();
d1.makeSound(2);
d2.showProfile();
d2.makeSound(3);
c1.showProfile();
c1.makeSound(5);
}
}
class Animal{
String name;
int age;
double weight;
Animal(String n, int a, double w)
{
name=n;
age=a;
weight=w;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,體重"+weight+"公斤.");
}
}
class Dog extends Animal
{
Dog(String n, int a, double w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1; i<=x; i++)
System.out.print("汪~");
System.out.println();
}
}
class Cat extends Animal
{
Cat(String n, int a, double w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1; i<=x; i++)
System.out.print("喵~");
System.out.println();
}
}
複製代碼
作者:
王法棣
時間:
2022-9-3 20:45
public class Ch68 {
public static void main(String[] args) {
Dog d1=new Dog("憨憨",2,1.28);
Dog d2=new Dog("球球",1,1.35);
Cat c1=new Cat("咪咪",3,0.95);
d1.showProfile();
d1.makeSound(2);
d2.showProfile();
d2.makeSound(3);
c1.showProfile();
c1.makeSound(5);
}
}
class Animal{
String name;
int age;
double weight;
Animal(String n,int a,double w){
name=n;
age=a;
weight=w;
}
void showProfile(){
System.out.println(name+"今年"+age+"歲,體重"+weight+"公斤。");
}
}
class Dog extends Animal{
Dog(String n,int a,double w){
super(n,a,w);
}
void makeSound(int x){
for(int i=0;i<x;i++)
System.out.print("汪~");
System.out.println();
}
}
class Cat extends Animal{
Cat(String n,int a,double w){
super(n,a,w);
}
void makeSound(int x){
for(int i=0;i<x;i++)
System.out.print("喵~");
System.out.println();
}
}
複製代碼
作者:
張博竣
時間:
2022-9-3 20:46
public class Ch69 {
public static void main(String[] args) {
Dog d1=new Dog("憨憨",2,1.28);
Dog d2=new Dog("球球",1,1.35);
Cat c1=new Cat("咪咪",3,0.95);
d1.showProfile();
d1.makeSound(2);
d2.showProfile();
d2.makeSound(3);
c1.showProfile();
c1.makeSound(5);
}
}
class Animal{
String name;
int age;
double weight;
Animal(String n, int a, double w)
{
name=n;
age=a;
weight=w;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,體重"+weight+"公斤.");
}
}
class Dog extends Animal
{
Dog(String n, int a, double w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1; i<=x; i++)
System.out.print("汪~");
System.out.println();
}
}
class Cat extends Animal
{
Cat(String n, int a, double w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1; i<=x; i++)
System.out.print("喵~");
System.out.println();
}
}
複製代碼
作者:
王秉鈞
時間:
2022-9-3 20:55
public class Ch32 {
public static void main(String[] args) {
Dog d1=new Dog("史東西",2,1.28);
Dog d2=new Dog("使冬吸",1,1.35);
Cat c1=new Cat("哈哈",3,0.95);
d1=showProfile();
d1=makeSound(2);
d2.showProfile();
d2=makeSound(3);
c1.showProfile();
c1=makeSound(5);
}
}
class Animal
{
String name;
int age;
double weight;
Animal(String n,int a,double w)
{
name=n;
age=a;
weight=w;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,體重"+weight+"公斤");
}
}
class Dog extends Animal
{
Dog(String n, int a,double w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1;i<=x;i++)
System.out.println("尢");
System.out.println();
}
}
class Cat extends Animal
{
Cat(String n,int a,double w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1;i<=x;i++)
System.out.println("ㄇㄧㄠ");
System.out.println();
}
}
複製代碼
作者:
呂尚霖
時間:
2022-9-3 20:55
public class Ch02
{
public static void main(String[] args)
{
Dog d1=new Dog("憨憨",2,1.28);
Dog d2=new Dog("球球",1,1.35);
Cat c1=new Cat("咪咪",3,0.95);
d1.showProfile();
d1.makeSound(2);
d2.showProfile();
d2.makeSound(3);
c1.showProfile();
c1.makeSound(5);
}
}
class Animal
{
String name;
int age;
double weight;
Animal(String n, int a, double w)
{
name=n;
age=a;
weight=w;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,體重"+weight+"公斤.");
}
}
class Dog extends Animal
{
Dog(String n, int a, double w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1; i<=x; i++)
System.out.print("汪~");
System.out.println();
}
}
class Cat extends Animal
{
Cat(String n, int a, double w)
{
super(n,a,w);
}
void makeSound(int x)
{
for(int i=1; i<=x; i++)
System.out.print("喵~");
System.out.println();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2