验证中...
7.21 杭州源创会火热报名中,一起来看看移动开发如何紧跟浪潮?
语言: Java
分类: 其他
最后更新于 2018-04-17 00:46
片段 1 片段 2 片段 3 片段 4 片段 5
Cat.java
原始数据 复制代码
package com.lmj.week05;
public class Cat extends Pet{
public Cat(String name, int age) {
super(name, age);
// TODO Auto-generated constructor stub
}
public void run() {
System.out.println("Cat is running");
}
public void talk() {
System.out.println("miaomiao");
}
public void zls() {
System.out.println("i can zls");
}
}
DOG.java
原始数据 复制代码
package com.lmj.week05;
public class DOG extends Pet{
public DOG(String name, int age) {
super(name, age);
// TODO Auto-generated constructor stub
}
public void run() {
System.out.println("DOG is running");
}
public void talk() {
System.out.println("wangwang");
}
public void swim() {
System.out.println("i can swim");
}
}
girlfriend.java
原始数据 复制代码
package com.lmj.week05;
public class girlfriend {
String name;
int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "girlfriend [name=" + name + ", age=" + age + "]";
}
public girlfriend(String name,int age) {
this.age=age;
this.name=name;
}
public void getpet(Pet pet) {
System.out.println("i got "+pet.toString());
}
}
Pet.java
原始数据 复制代码
package com.lmj.week05;
public class Pet {
String name;
int age;
@Override
public String toString() {
return "Pet [name=" + name + ", age=" + age + "]";
}
public Pet(String name2, int age2) {
this.age=age2;
this.name=name2;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void run() {
System.out.println("pet is running");;
}
public void talk() {
System.out.println("pet talk");;
}
}
PetszDemo.java
原始数据 复制代码
package com.lmj.week05;
public class PetszDemo {
public static void main(String args[]) {
Pet[] petlist= {
new DOG("dog1",1),
new Cat("cat1",1)
};
for(int i=0;i<petlist.length;i++) {
System.out.println(petlist[i].toString());
}
}
}

评论列表( 0 )

你可以在登录后,发表评论

11_float_left_people 11_float_left_close