Abstract class 的驱动程序
Driver program for Abstract class
我是 Java 的新手。我一直在研究抽象的概念 class。
我了解抽象 classes 无法实例化。所以一个抽象的 subclass 不能在抽象基 class.
中用 new 实例化
但是,我一直在寻找一个driver/main class 是抽象的学习,因为不允许实例化。
示例:
public abstract class Research{
public static void main(String [] args){
[Code here
}
}
谁能解释一下 driver/main class 的摘要 class 会是什么样子?
谢谢。
抽象这个词应该暗示你它不是真实的。这就是为什么你不能触摸那个class(比如界面)的真实实例。但是 asbtract class 可以有一些方法实现(接口没有)。为了测试已经实现的方法,只需使用一些存根扩展 class 并测试已经实现的方法。
让我们说
abstract class AbstractClass{
implementedMethod(){ //some code}
abstractMehod()
}
class ExtendedClass extends AbstractClass{
abstractMethod(){//implementation}
public static void main(String args[ ]) {
//here you can drive
}
}
无法实例化抽象class
public abstract class Person {
// hi i am an abstract person
// put your abstract methods here
}
public class Student extends Person {
// This class provides the implementation of the abstract methods in the Person abstract class
// implement the abstract methods of Person
}
public class Driver {
public static void main(String[] args) {
// Person p = new Person(); // wrong
Student s = new Student();
}
}
参见 https://docs.oracle.com/javase/tutorial/java/IandI/abstract.html 它详细解释了 Java 中的摘要 class。
我是 Java 的新手。我一直在研究抽象的概念 class。
我了解抽象 classes 无法实例化。所以一个抽象的 subclass 不能在抽象基 class.
中用 new 实例化但是,我一直在寻找一个driver/main class 是抽象的学习,因为不允许实例化。
示例:
public abstract class Research{
public static void main(String [] args){
[Code here
}
}
谁能解释一下 driver/main class 的摘要 class 会是什么样子? 谢谢。
抽象这个词应该暗示你它不是真实的。这就是为什么你不能触摸那个class(比如界面)的真实实例。但是 asbtract class 可以有一些方法实现(接口没有)。为了测试已经实现的方法,只需使用一些存根扩展 class 并测试已经实现的方法。 让我们说
abstract class AbstractClass{
implementedMethod(){ //some code}
abstractMehod()
}
class ExtendedClass extends AbstractClass{
abstractMethod(){//implementation}
public static void main(String args[ ]) {
//here you can drive
}
}
无法实例化抽象class
public abstract class Person {
// hi i am an abstract person
// put your abstract methods here
}
public class Student extends Person {
// This class provides the implementation of the abstract methods in the Person abstract class
// implement the abstract methods of Person
}
public class Driver {
public static void main(String[] args) {
// Person p = new Person(); // wrong
Student s = new Student();
}
}
参见 https://docs.oracle.com/javase/tutorial/java/IandI/abstract.html 它详细解释了 Java 中的摘要 class。