java编程!谢谢!编一个应用抽象类程序,并将抽象类改为接口。
编写一个应用抽象类程序,设计抽象类并实现抽象类中抽象方法的子类。将上题中的抽象类改写为接口,实现相同的功能。。。谢谢!!!!...
编写一个应用抽象类程序,设计抽象类并实现抽象类中抽象方法的子类。将上题中的抽象类改写为接口,实现相同的功能。。。谢谢!!!!
展开
展开全部
设计抽象类并实现抽象类中抽象方法的子类
抽象类: Person_abstract
public abstract class Person_abstract {
public abstract void eat();
public void show(){
System.out.println("我是人");
}
}
实现类1:Student_abstract
public class Student_abstract extends Person_abstract {
public void eat() {
System.out.println("student eat!!!");
}
public void show(){
System.out.println("我是student");
}
}
实现类2:Teacher_abstract
public class Teacher_abstract extends Person_abstract {
public void eat() {
System.out.println("teacher eat!!!");
}
public void show(){
System.out.println("我是teacher");
}
}
--------------------------------------------------分割线----------------------------
抽象类改写为接口,实现相同的功能
接口:Person_Interface
public interface Person_Interface {
public void eat();
public void show();
}
实现类1:Student_Interface
public class Student_Interface implements Person_Interface{
public void eat() {
System.out.println("student eat!!!");
}
public void show() {
System.out.println("我是student");
}
}
实现类2:Teacher_Interface
public class Teacher_Interface implements Person_Interface{
public void eat() {
System.out.println("teacher eat!!!");
}
public void show() {
System.out.println("我是teacher");
}
}
---------------------------------分割线-----------------------------
应该ok了吧 一个抽象类,一个接口,都分别写了两个实现类。
抽象类: Person_abstract
public abstract class Person_abstract {
public abstract void eat();
public void show(){
System.out.println("我是人");
}
}
实现类1:Student_abstract
public class Student_abstract extends Person_abstract {
public void eat() {
System.out.println("student eat!!!");
}
public void show(){
System.out.println("我是student");
}
}
实现类2:Teacher_abstract
public class Teacher_abstract extends Person_abstract {
public void eat() {
System.out.println("teacher eat!!!");
}
public void show(){
System.out.println("我是teacher");
}
}
--------------------------------------------------分割线----------------------------
抽象类改写为接口,实现相同的功能
接口:Person_Interface
public interface Person_Interface {
public void eat();
public void show();
}
实现类1:Student_Interface
public class Student_Interface implements Person_Interface{
public void eat() {
System.out.println("student eat!!!");
}
public void show() {
System.out.println("我是student");
}
}
实现类2:Teacher_Interface
public class Teacher_Interface implements Person_Interface{
public void eat() {
System.out.println("teacher eat!!!");
}
public void show() {
System.out.println("我是teacher");
}
}
---------------------------------分割线-----------------------------
应该ok了吧 一个抽象类,一个接口,都分别写了两个实现类。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询