Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Java - Constructor Program
WhatsApp
Senthilvelan Sambamoorthy
Jul 31
2016
509
0
0
class
cons
{
int
l;
int
b;
cons()
// default constructor
{ l=
1
;
b=
2
;
}
cons(
int
tl)
// function name is same as class name
{ l=tl;
b=
4
;
}
cons(
int
tl,
int
tb)
// class name same as function name with different parameter
{ l=tl;
b=tb;
}
void
display()
{
System.out.println(
"\n"
);
System.out.println(
"Length of the rectangle = "
+l);
System.out.println(
"Breadth of the rectangle = "
+b);
}
public
static
void
main(String arg[])
{
cons r1=
new
cons();
r1.display();
cons r2=
new
cons(
6
);
r2.display();
cons r3=
new
cons(
10
,
20
);
r3.display();
}
}
Java
Constructor Program
Up Next
Java - Constructor Program