Java constructor of an abstract class

Maxim

As far as I know (please correct me if I'm wrong) a class that is abstract cannot be instantiated. You can give it a constructor, but just can't call new on that class. If you call super in a subclass, the superclass constructor will run (and thus create an object of that class?) then how come you can actually call super in a subclass of an abstract class? I'm sure it has something to do with my misunderstanding about a constructor making an object...

Luiggi Mendoza

If you call super in a subclass, the superclass constructor will run (and thus create an object of that class??) then how come you can accually call super in a subclass of an abstract class?

This part is wrong. When you call super in the subclass constructor, you're just telling to the subclass that it first has to execute the initialization code from the super class (abstract or not), then it will continue executing the code to initialize the current instance of the class being created. This doesn't mean that it will create an instance of the super class in the middle of the creation of the current instance.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Java abstract class, abstract constructor

From Dev

Java abstract class constructor

From Dev

Java constructor of a subclass of an abstract class

From Dev

Why is the need of Protected constructor in Abstract class in java

From Dev

Constructor to interface/abstract class using Java generics

From Dev

java call method in constructor and abstract class?

From Dev

using constructor in abstract class

From Dev

Calling the constructor of an abstract class

From Dev

Abstract class constructor initialization

From Dev

Call constructor in an abstract class

From Dev

Call constructor in an abstract class

From Dev

How do test an abstract class's constructor logic in Java

From Dev

Instance of abstract class with hidden constructor

From Dev

Testing abstract class constructor with JUnit

From Java

Can an abstract class have a constructor?

From Dev

Call constructor in abstract class with generics

From Dev

abstract class vs private constructor

From Dev

Private constructor in abstract class Scala?

From Dev

Benefits of an abstract class with a factory constructor?

From Dev

Constructor injection on abstract class and children

From Dev

Call constructor in abstract class with generics

From Dev

Private constructor in abstract class Scala?

From Dev

Mocking an abstract method, but not the class constructor

From Dev

Abstract Method In Abstract Class In java

From Dev

Abstract class with constructor, force inherited class to call it

From Dev

Derived Class Constructor from an Abstract Class

From Dev

Abstract Classes - Super Constructor (Java)

From Dev

instantiating an abstract class in JAVA?

From Dev

simple abstract class in java

Related Related

HotTag

Archive