TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Java - Constructor Program
Senthilvelan Sambamoorthy
Jul 31
2016
Code
484
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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