4 回答
TA贡献1811条经验 获得超6个赞
您可以将您的课程移到外面或使它们成为静态的。
public abstract class Employee {
public abstract void names();
}
public class Banani extends Employee {
@Override
public void names() {
System.out.println("I am at Banani.");
}
}
public class Shyamoli extends Employee {
@Override
public void names() {
System.out.println("I am at Shyamoli");
}
}
class javatest {
public static void main(String[] args) {
Employee south = new Banani();
Employee north = new Shyamoli();
north.names();
south.names();
}
}
TA贡献1803条经验 获得超6个赞
更正的代码如下
abstract class Employee {
public abstract void names();
public abstract void offices();
}
class Banani extends Employee {
@Override
public void names() {
System.out.println("I am at Banani.");
}
@Override
public void offices() {
// TODO Auto-generated method stub
}
}
class Shyamoli extends Employee {
@Override
public void names() {
System.out.println("I am at Shyamoli");
}
@Override
public void offices() {
// TODO Auto-generated method stub
}
}
public class javatest {
public static void main(String[] args) {
Employee south = new Banani();
Employee north = new Shyamoli();
north.names();
south.names();
}
}
添加回答
举报