• Post Reply Bookmark Topic Watch Topic
  • New Topic

Constructors  RSS feed

 
Manaf Abdul
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can someone tell me two exact uses of a constructor please?
 
khadar valli
Greenhorn
Posts: 26
Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abdul,

Constructor is a method with which you can initialize some parameters at the time of creating an object. When the object is created, Java calls the constructor first(default constructor). Any code you have in your constructor will then get executed. You don't need to make any special calls to a constructor method - they happen automatically when you create a new object.

May be this will help you to understand the constructors.

Regards,
Khadar.
 
Manaf Abdul
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
khadar valli wrote:

Constructor is a method with which you can initialize some parameters at the time of creating an object. When the object is created, Java calls the constructor first(default constructor). Any code you have in your constructor will then get executed. You don't need to make any special calls to a constructor method - they happen automatically when you create a new object.

May be it will helpful to you to understand the constructors.

Regards,
Khadar.


i want 2 exact points on uses of constructors
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manaf Abdul wrote:i want 2 exact points on uses of constructors

Hi Manaf, and welcome to JavaRanch.

What do you mean by "exact points"?

Khadar has given you a perfectly good explanation of what a constructor is and what they're used for, so it's now up to you to explain why that's not good enough.

I suggest you read our HowToAskQuestionsOnJavaRanch page. It will help you to get answers quicker and more precisely.

Winston
 
Campbell Ritchie
Marshal
Posts: 55781
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
khadar valli wrote:Hi Abdul,

Constructor is a method . . .
I am afraid that is not actually correct; a constructor is not a method. It looks like a method but there are big differences. For one thing you cannot call a constructor apart from use of the new operator.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!