java抽象类与接口 中 相同方法的调用
来源:百度知道 编辑:UC知道 时间:2024/05/23 23:36:24
abstract class mm
{
public abstract void play();
}
interface tt
{
void play();
}
public class Inte extends mm implements tt
{
public static void main(String args[])
{
new Inte().play();
}
public void play()
{
System.out.println("我正在玩^^^^^^^^");
}
}
希望对你有所帮助
interface MyInterface {
public void m();
}
abstract class MyClass {
public void m() {
System.err.println("asdfasdfasdf");
}
}
public class InterfaceClassInherit extends MyClass implements MyInterface {
public static void main(String[] args) {
MyInterface obj = new InterfaceClassInherit();
obj.m();
}
}
在上面的程序中,接口MyInterface和抽象类MyClass中均有一个名为m()的无返回类型的函数.当某类继承MyClass类和实现MyInterface接口时,类中的m()方法覆盖了继承自接口的m()方法,相当于重写了这个方法.
用接口MyInterface声明一个指向自创类对象的引用.该引用在调用m()方法时调用的是自