answersLogoWhite

0


Best Answer

No. You must create a subclass of the abstract class in order to be able to instantiate it.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you instantiate an abstract class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you call an abstract class from main method?

An abstract class cannot have a constructor and hence you cannot invoke the constructor of the class - i.e., you can instantiate an abstract class and hence you cannot call the constructor of an abstract class.


Create an instance to an abstract class?

You cannot create an instance of an abstract class. For ex: Public abstract AbsTest { … } AbsTest ex = new AbsTest(); Lets say we have a class declaration AbsTest that is abstract and then I try to instantiate it, the compiler will give me an error stating that "An Abstract class cannot be instantiated"


Why we can't create object for Container class using new keyword?

It is an abstract class so you can't instantiate it directly, but have to use a subclass instead.


Can you have a final abstract class?

No. The abstract keyword means that you cannot instantiate the class unless you extend it with a subclass. The final keyword means that you cannot create subclasses of that class.Combining them would lead to an unusable class, so the compiler will not let this happen.


Can abstract class have constructors?

A constructor of a class in invoked when a object of that class is created. As an abstract class can't have an object, so we can't create a constructor of the abstract class. But we can create a constructor of a concrete subclass of that abstract class and we have to pass the object of that concrete subclass to the abstract class.


How do you achieve abstraction in java?

Abstraction in Java is achieved using interfaces and abstract class. abstract means something which is not complete or concrete but abstraction itself is a great programming concept and allow you to write code which is more flexible to change.


A final class can have instances?

Yes. You cannot inherit a final class but very well instantiate a final class


What is abrstac class and virctulfunction in c sharp?

abstract class is a class label with abstract. It is just like a common class, with the following characterics: 1. Abstract class cannot be instantiate with an instance. 2. Abstract class may have abstract methods, while the normal class cannot have abstract methods. a virtual function in C# is a way to provide a default implementation for the class hierarchy. Both abstract class and common class (not sealed) can have virtual methods/ functions. Note that an abstract method (of an abstract class) is defining the intent, no codes (no default behavior), the implementation are left for the derived classes to do so. The virtual function if defined in an abstract class must define the implementation, the minimum is to do nothing: public abstract class Vehicle { public abstract int GetNumberOfTires(); public virtual void Move() { // default is doing nothing} } public class Car : Vehicle { public override int GetNumberOfTires() { return 4; } public override void Move() { throws new OutOfFuelExpection(); } }


Can a class in java extend both abstract class and concrete class?

An Abstract class is similar to an interface. You cannot instantiate them, but you can extend them. Any class that extends the abstract class has to provide the implementation to the abstract methods. Hence these classes can be used as a skeleton to similar classes where some common functionality may be required. Such functionality can also be embedded into these classes. Unlike interfaces, abstract classes can have method code also. So they are very useful.


When should a class be declared abstract?

In two situations:You want the child class to provide certain behavior while making sure that certain other behavior is as you want it (Through the concrete methods that you create)You dont want any other class to be able to instantiate your class


What is abstaction in java?

The concept of abstraction is concept talked about when talking about inheritance. When you make a class abstract, it means that the class is a general "abstract" idea, not something you want to instantiate (create an object from.) However, abstract classes are useful for when you want to create real sub-classes of the abstract class. For example, you could have an abstract class named "animal" that had the general characteristics of all animals, then you can have regular sub-classes that inherit "animal", like "dog", "cat" or "horse." The reason for making the "animal" class abstract is to make sure that one can't create a generic "animal" object, but so they can create objects that inherit the idea of "animal."


What are the differences between class and abstract class?

Below is the main difference between the 3 components:Concrete class - Provides implementation for all its methods & also for methods from extended abstract classes or implemented interfacesAbstract class - Does not provide implementation for one or more of its methodsInterface - Does not provide implementation for any of its methods