Can Abstract Class have a Constructor?

0 votes
Constructors in abstract class-how can it be used and for what purposes?
May 11, 2018 in Java by Daisy
• 8,090 points
147 views

1 answer to this question.

0 votes

Yes, an abstract class can have a constructor. Since an abstract class can have variables of all access modifiers, they have to be initialized to default values, so constructor is necessary. As you instantiate the child class, constructor of abstract class is invoked and variables are initialized.

On the contrary, an interface does contain only constant variables means they are already initialized. Thus, an interface does not need a constructor

answered May 11, 2018 by sharth
• 3,370 points

Related Questions In Java

0 votes
1 answer

Is there a way to instantiate abstract class ?

No, you are not creating the instance ...READ MORE

answered Dec 12, 2018 in Java by Sushmita
• 6,890 points
1,508 views
0 votes
1 answer

JsonMappingException: No suitable constructor found for type [simple type, class ]: can not instantiate from JSON object?

Hello @kartik, his happens for these reasons: your inner ...READ MORE

answered Apr 8 in Java by Niroj
• 23,750 points
283 views
0 votes
2 answers

How to call one constructor from another in Java?

public class Cons { public static Cons ...READ MORE

answered Jul 24, 2018 in Java by Akrati
• 3,150 points
505 views
0 votes
1 answer

How to set a timer in Java?

To work on timer in java, you ...READ MORE

answered May 16, 2018 in Java by Daisy
• 8,090 points
94 views
0 votes
2 answers

When and how to use Super() keyword in Java?

super() is used to call immediate parent. super() can be ...READ MORE

answered Jul 9, 2018 in Java by Sushmita
• 6,890 points
274 views
0 votes
1 answer

Use of Static Keyword in a Class

It means that there is only one ...READ MORE

answered May 28, 2018 in Java by Rishabh
• 3,580 points
101 views
0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 53,110 points
390 views
0 votes
1 answer

what are the ways in which a list can be iterated

  There are 5 ways to iterate over ...READ MORE

answered Apr 23, 2018 in Java by sharth
• 3,370 points
146 views