Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an abstract class be used as a reference type?

Tags:

java

abstract

I'm not so sure what that would imply and my textbook is dancing around the answer.

like image 255
nogamo Avatar asked Nov 19 '10 00:11

nogamo


People also ask

Can an abstract be used as a reference type?

It is preferable to cite the full text of a work, but abstracts can be used as sources and included in the reference list IF you indicate as such in the citation.

Can abstract classes be used as types?

The abstract type is often used as a return type (because you don't want the caller to know what concrete type is returned: it could change later, or could vary based on the arguments of the configuration).

Can we create object reference of abstract class?

We cannot create objects of an abstract class. To implement features of an abstract class, we inherit subclasses from it and create objects of the subclass. A subclass must override all abstract methods of an abstract class. However, if the subclass is declared abstract, it's not mandatory to override abstract methods.

Can we create reference of abstract class in C#?

Yes, we can create a reference for the abstract class in C#.


1 Answers

Yes you can:

abstract class AbstractClass {

}

class DeclaredClass extends AbstractClass {

}

AbstractClass c = new DeclaredClass();

The above is perfectly valid.

like image 64
jjnguy Avatar answered Sep 20 '22 23:09

jjnguy