Constructors are used to create objects from the class. Constructor declaration are just like method declaration, except that they do not have any return type and they use the name of the class. The compiler provides us with a default constructor to the class having no arguments.
Inheritance is one of the concept of the Object- Oriented programming. The advantage of using the inheritance is
It allows you to define a general class, and later more specialized classes by simply adding some new details. The properties of the parent class will automatically will be inherited by the base class.
The code of the program is given below:
<title>Working With Constructors and Inheritance</title>
<h1>Working With Constructors and Inheritance</h1>
Rectangle() throws java.io.IOException
Rectangle(int length, int breadth) throws java.io.IOException
this.length = length;
this.breadth = breadth;
area = length*breadth;
pw.println("In Rectangle constructor...<br>");
class Square extends Rectangle
Square(int length, int breadth) throws java.io.IOException
pw.println("In Square constructor...<br>");
pw = out;
Square obj = new Square(10,10);
The output of the program is given below:
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.