Pin It

Inheritance in Java : Constructor with arguments

Program to demonstrate Constructor with arguments in Java Inheritance

package com.hubberspot.code;

class Drawing {
 
  public Drawing(int d){
     System.out.println("Drawing Constructor called " +
   "with argument as "+ d);
  }  
}

class Shape extends Drawing{
 
  public Shape(int i){
     super(11); // Compile time error if skipped
     System.out.println("Shape Constructor called " +
   "with argument as "+ i);
  } 
}

public class Circle extends Shape{
 
  public Circle(){
     super(10); // Compile time error if skipped
     System.out.println("Circle Constructor called");
  }
 
  public static void main(String[] args) {
  
     Circle circle = new Circle();
 
  }

}




Output of the program :




Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot