answersLogoWhite

0


Best Answer

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.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

No. An abstract class is an incomplete class. It does not have all functionality and features implemented in it. So, you cannot instantiate it.

If you try to call the constructor for an abstract class, you will get a compilation error

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

abstract class in java is mainly designed for giving abstract method i.e declarations alone, Instantiation is a process by which jvm allocates memory for that. But only with the method declaration jvm will not know how much memory should give for the abstract method. So abstract classes are no need to instantiate before the method implementation, The concrete class which extends the abstract class, will provide method implementation at that time only abstract class constructor will run

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

If you do not provide an explicit constructor to the class weather it may be an abstract or normal class , in this situation JVM provides you a default constructor. you can also create an explicit constructor. By using SUPER keyword you might be call constructor of abstract class but it is not possible to call constructor of abstract class using NEW keyword.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

The constructor is used to initialize objects - to prepare them the moment they are created. This is the same in an abstract class as in any other class. The object will simply be created from a subclass of the abstract class, but a constructor may still be useful.

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

Yes. Abstract class can have constructor which is called when an instance is created for it's concrete class.... satish koleti

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can abstract class have constructors
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How can you identify a constructor from among any other methods in a class?

Constructors have the same identifier as that of the class, so if the name of your class is Book then your constructor must also be named Book. Constructors have no return type, not even void.


What is an abstract class Write the syntax Declare a pure virtual function in an abstract class?

an abstract class is nothing but class which contains both abstract and concrete methods for abstract class we r nt create object Syntax for pure abstract class is abstract class x { public void abstract y(); public void abstract z(); public void abc() { }


What is the difference between abstract class and normal class?

Any class which has one or more abstract methods is called an abstract class. But in the normal class we can't have any abstract methods. We cannot create an object for the abstract classes. When we inherit the abstract class we should implement the abstract method which we inherit.


How many constructors does class Exception have?

The Exception class has 4 constructors. They are: a. Exception() b. Exception(String arg) c. Exception(String arg, Throwable arg1) d. Exception(Throwable arg)


What is the difference between default constructor and parameterized constructor?

A default constructor is one that has no parameters (C++ also calls constructors with all default parameters a default constructor), while a parameterized constructor is one that has at least one parameter without a default value. Default constructors can be provided by the compiler if no other constructors are defined for that class or any class the class inherits from, while parameterized constructors must always be defined by the developer.

Related questions

What are different type of constructor in java?

Every class, including abstract classes, MUST have a constructor. The different types are: a. Regular constructors b. Overloaded constructors and c. Private constructors


What happens if an abstract modifier is applied to class. Explain?

The classes which have one or more abstract methods are abstract. To declare a class as abstract, use the abstract keyword in front of the class keyword, before the class declaration. Abstract classes cannot be instantiated. Similarly the new keyword cannot be used to create an object of the abstract class. Remember that the constructors and static variables cannot be declared as abstract. Any subclass of an abstract class must either implement all of the abstract methods in the superclass or be itself declared abstract.


For what purpose constructors are used in Java?

Constructors are used to create the instance of a class.


What is the use of constructors?

Constructors are used in object-oriented programming languages to create usable instances of abstract data types (classes).


What is the similarity between abstract class and class?

They provide the same level of abstraction and encapsulation, and similar inheritance. The differences in inheritance: an abstract class forces you to have at least 1 subclass (otherwise this abstraction branch is useless, because you won't be able to create any instance), while a non-abstract class may have optional subclasses.


How can you identify a constructor from among any other methods in a class?

Constructors have the same identifier as that of the class, so if the name of your class is Book then your constructor must also be named Book. Constructors have no return type, not even void.


Why you use constructors?

To create an instance of the class that implementing that constructor


What is an abstract class Write the syntax Declare a pure virtual function in an abstract class?

an abstract class is nothing but class which contains both abstract and concrete methods for abstract class we r nt create object Syntax for pure abstract class is abstract class x { public void abstract y(); public void abstract z(); public void abc() { }


What is main advantage of using constructors in java?

Constructors have the same name as the class itself and they do not specify a return type, not even void because they return the instance of the class itself. Because constructors have the same name as the class then they allow method overloading and also save memory and execution time of program. Program release memory of constructors function after using this function and it reduce program complexity.


What is the difference between abstract class and normal class?

Any class which has one or more abstract methods is called an abstract class. But in the normal class we can't have any abstract methods. We cannot create an object for the abstract classes. When we inherit the abstract class we should implement the abstract method which we inherit.


How many constructors does class Exception have?

The Exception class has 4 constructors. They are: a. Exception() b. Exception(String arg) c. Exception(String arg, Throwable arg1) d. Exception(Throwable arg)


What is the difference between default constructor and parameterized constructor?

A default constructor is one that has no parameters (C++ also calls constructors with all default parameters a default constructor), while a parameterized constructor is one that has at least one parameter without a default value. Default constructors can be provided by the compiler if no other constructors are defined for that class or any class the class inherits from, while parameterized constructors must always be defined by the developer.