有抽象方法的类,必须定义为抽象类;
还有继承了抽象类,就必须得实现该抽象方法。
可以这样:
import java.io.*;
abstract class Exbase{
abstract public void martiey();
}
class MyEx extends Exbase{
public static void main(String[] args){
DataInputStream fi = new DataInputStream(System.in);
try{
fi.readChar();
}catch(IOException e){
System.exit(0);
}finally{
System.out.println("Doing finally");
}
}
@Override
public void martiey() {
// TODO Auto-generated method stub
}
}
还有继承了抽象类,就必须得实现该抽象方法。
可以这样:
import java.io.*;
abstract class Exbase{
abstract public void martiey();
}
class MyEx extends Exbase{
public static void main(String[] args){
DataInputStream fi = new DataInputStream(System.in);
try{
fi.readChar();
}catch(IOException e){
System.exit(0);
}finally{
System.out.println("Doing finally");
}
}
@Override
public void martiey() {
// TODO Auto-generated method stub
}
}
本文介绍了在Java中如何使用抽象类及其实现抽象方法的基本概念。通过示例代码展示了定义抽象类与方法的过程,以及继承抽象类并实现其抽象方法的具体步骤。
318

被折叠的 条评论
为什么被折叠?



