Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中的抽象类。_Java_Scjp - Fatal编程技术网

Java中的抽象类。

Java中的抽象类。,java,scjp,Java,Scjp,它是指抽象类的间接实例化吗?怎么办 我们能做到这一点吗? 就像我试过几次一样。。它给出了一个错误:有人对此做过什么吗 abstract class hello //abstract class declaration { void leo() {} } abstract class test {} //2'nd abstract class class dudu { //main class p

它是指抽象类的间接实例化吗?怎么办 我们能做到这一点吗? 就像我试过几次一样。。它给出了一个错误:有人对此做过什么吗

    abstract class hello //abstract class declaration 
    { 
    void leo() {}
    }             


    abstract class test {} //2'nd abstract class 


    class dudu {  //main class 

    public static void main(String args[]) 
    {
    hello d = new test() ;  // tried here 
    }

    }

不能实例化抽象类。抽象类的整体思想是声明子类之间的共同点,然后对其进行扩展

  public abstract class Human {
         // This class can't be instantiated, there can't be an object called Human
         }

  public Male extends Human {
         // This class can be instantiated, getting common features through extension from Human class
   } 

  public Female extends Human {
        // This class can be instantiated, getting common features through extension from Human class

   } 

更多信息:

您不能实例化抽象类。抽象类的整体思想是声明子类之间的共同点,然后对其进行扩展

  public abstract class Human {
         // This class can't be instantiated, there can't be an object called Human
         }

  public Male extends Human {
         // This class can be instantiated, getting common features through extension from Human class
   } 

  public Female extends Human {
        // This class can be instantiated, getting common features through extension from Human class

   } 

更多信息:

我们不能实例化一个抽象类。如果我们想扩展它,就必须扩展它。

我们不能实例化一个抽象类。如果我们想扩展它,就必须扩展它。

你不能创建抽象类的实例,我想这就是你要做的

abstract class hello //abstract class declaration 
{ 
    void leo() {}
}             

class test extends hello 
{
    void leo() {} // Custom test's implementation of leo method
}

你们不能创建抽象类的实例,我想这就是你们要做的

abstract class hello //abstract class declaration 
{ 
    void leo() {}
}             

class test extends hello 
{
    void leo() {} // Custom test's implementation of leo method
}

不能在java中为抽象类创建对象。
请参阅此链接-

您无法在java中为抽象类创建对象。 请参阅此链接-

它是指我对抽象类的间接实例化吗?我们如何做到这一点

我需要了解使用该短语的上下文,但我希望“间接实例化”意味着对扩展抽象类的非抽象类进行实例化

比如说

public abstract class A {
    private int a;
    public A(int a) {
       this.a = a;
    }
    ...
}

public B extends A {
    public B() {
        super(42);
    } 
    ...
}

B b = new B();    // This is an indirect instantiation of A
                  // (sort of ....)

A a = new A(99);  // This is a compilation error.  You cannot
                  // instantiate an abstract class directly.
它是指我对抽象类的间接实例化吗?我们如何做到这一点

我需要了解使用该短语的上下文,但我希望“间接实例化”意味着对扩展抽象类的非抽象类进行实例化

比如说

public abstract class A {
    private int a;
    public A(int a) {
       this.a = a;
    }
    ...
}

public B extends A {
    public B() {
        super(42);
    } 
    ...
}

B b = new B();    // This is an indirect instantiation of A
                  // (sort of ....)

A a = new A(99);  // This is a compilation error.  You cannot
                  // instantiate an abstract class directly.

test不扩展hello,所以使用hello类型的变量引用test类型的对象是没有意义的。根据定义,抽象类不能被实例化。因此,调用new test()也没有意义。请重新阅读关于继承和抽象类的教科书。并遵守Java命名约定:类以大写字母开头。如果用具体类对抽象类进行子类化,并覆盖其所有抽象方法,则在实例化子类时,会自动间接实例化抽象类。术语“间接”并不常见,但我猜您可能是指,因为无法直接实例化抽象类。test不扩展hello,因此使用hello类型的变量引用类型test的对象没有意义。根据定义,抽象类不能被实例化。因此,调用new test()也没有意义。请重新阅读关于继承和抽象类的教科书。并遵守Java命名约定:类以大写字母开头。如果用具体类对抽象类进行子类化,并覆盖其所有抽象方法,则在实例化子类时,会自动间接实例化抽象类。术语“间接”并不常见,但我想你可能是这个意思,因为没有直接实例化抽象类的方法。我基本上是在问“间接实例化”?@Akshay:我们不知道你的意思。请发一封有意义的推荐信。你的代码无法编译。@Akshay你为什么说间接实例化?如果您的意思是声明一个引用变量,然后给它分配一个不同的对象。如果类具有继承关系,则可能发生这种情况。e、 g:超类A=新的子类();我基本上是在问“间接实例化”?@Akshay:我们不知道你说的是什么意思。请发一封有意义的推荐信。你的代码无法编译。@Akshay你为什么说间接实例化?如果您的意思是声明一个引用变量,然后给它分配一个不同的对象。如果类具有继承关系,则可能发生这种情况。e、 g:超类A=新的子类();