Can you have a constructor in abstract class?

Answer Posted / rajesh dangi

I don't understand why ppl start writing responses without
writing a small code to confirm it.

Guys an abstract class too can have a constructer. Any time
a class inheriting an abstract class is instantiated, its
constructer would first call the constructor of the
abstract class. Try it yourself.
Plus, the method in the abstract class with the same name
(i.e. its constructer) is always considered as a
constructer and not any regular method. Even when the
constructer is public, you can not invoke the constructer
of an abstract class in a sub class inheriting the abstract
class. That method can not be invoked by our code since it
is an abstract class and can not be instantiated by us

Is This Answer Correct ?    62 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why singleton class is used in java?

575


What is use of super keyword?

567


How does compareto method work?

524


List out five keywords related to exception handling ?

600


What happens if main method is not static?

498






'A class is a template for an object' explain this statement.

546


What is difference between jdk,jre and jvm?

568


Which is bigger float or double java?

525


What is set in java?

531


How do you create a reference in java?

512


How do you create a bulleted list?

567


What is a control variable example?

529


What is the difference between compile-time polymorphism and runtime polymorphism?

568


What is return data type?

561


What are the advantages of exception handling?

556