0% found this document useful (0 votes)
3 views1 page

Java Constructor Overloading Example

The document presents a Java program demonstrating constructor overloading with a class named 'constructor'. It includes a non-parameterized constructor that prints a message and a parameterized constructor that calculates and prints the square of an integer. The main method creates instances of the class, triggering both constructors and displaying the corresponding output.

Uploaded by

Haris Balaji
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Java Constructor Overloading Example

The document presents a Java program demonstrating constructor overloading with a class named 'constructor'. It includes a non-parameterized constructor that prints a message and a parameterized constructor that calculates and prints the square of an integer. The main method creates instances of the class, triggering both constructors and displaying the corresponding output.

Uploaded by

Haris Balaji
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program for constructor overloading:

class constructor{
constructor(){
[Link]("Non-parameterized constructor");
}
constructor(int x){
[Link]("Parameterized Constructor: Square = "+x*x);
}
}
public class Main
{
public static void main(String[] args) {
constructor ob=new constructor();
constructor ob1=new constructor(6);
}
}

Output:
Non-parameterized constructor
Parameterized Constructor: Square = 36

You might also like