top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Can abstract class have constructors in Java?

+3 votes
408 views
Can abstract class have constructors in Java?
posted Apr 5, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

Yes.

Take for example this simple code:

public abstract class A {
  A() {
      build();
  }

  abstract void build();
}

public class B extends A {

    void build() {
        System.out.println("Building a B object..");
    }

    public static void main(String[] args) {
        new B();
    }

}
answer Apr 7, 2015 by Berci Pécsi
Similar Questions
0 votes

Can I declare an abstract class with no abstract methods in it in Java, if yes then how?

+2 votes

What is the difference between abstract class and concrete class in java. If concrete class is final then how can inherit concrete class, can someone please explain in detail?

...