Java Program to Create an Abstract Class With the Constructor

You are currently viewing Java Program to Create an Abstract Class With the Constructor

Java program to create an abstract class with the constructor

// Java program to create an abstract class 
// with the constructor

abstract class AbsClass {
  abstract void MyFun();

  AbsClass() {
    System.out.println("AbsClass: constructor called");
  }
}

class Sample extends AbsClass {
  Sample() {
    System.out.println("Sample: constructor called");
  }

  void MyFun() {
    System.out.println("Sample: MyFun() called");
  }
}

public class Main {
  public static void main(String[] args) {
    AbsClass abs = new Sample();
    abs.MyFun();
  }
}

Output

AbsClass: constructor called
Sample: constructor called
Sample: MyFun() called

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply