Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Constructor

This is a discussion on Constructor within the Java forums, part of the Software Development category; How constructor is advantageful?...

Go Back   Geeks Talk > Software Development > Java
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read

Java Java related Issues and Problems

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-01-2008
Junior Member
 
Join Date: Sep 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
kranti_435 is on a distinguished road
Constructor

How constructor is advantageful?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-01-2008
Expert Member
 
Join Date: Apr 2008
Location: Tamilnadu
Posts: 1,461
Thanks: 15
Thanked 150 Times in 141 Posts
deepasree has a spectacular aura aboutdeepasree has a spectacular aura about
Re: Constructor

hi friend..

Every class has at least one it's own constructort. Constructor creates a instance for the class. Constructor initiates (initialize) something related to the class's methods. Constructor is the method which name is same to the class. But there are many difference between the method (function) and the Constructor.

In this example we will see that how to to implement the constructor feature in a class. This program is using two classes. First class is another and second is the main class which name is Construct. In the Construct class two objects (a and b) are created by using the overloaded another Constructor by passing different arguments and calculated the are of the different rectangle by passing different values for the another constructor.

class another{
int x,y;
another(int a, int b){
x = a;
y = b;
}
another(){
}
int area(){
int ar = x*y;
return(ar);
}
}
public class Construct{
public static void main(String[] args)
{
another b = new another();
b.x = 2;
b.y = 3;
System.out.println("Area of rectangle : " + b.area());
System.out.println("Value of y in another class : " + b.y);
another a = new another(1,1);
System.out.println("Area of rectangle : " + a.area());
System.out.println("Value of x in another class : " + a.x);
}
}

Thanks
Deepasree
Reply With Quote
Reply

  Geeks Talk > Software Development > Java

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
constructor emb.mallik C and C++ 1 03-02-2009 04:50 PM
Copy Constructor manoj200724 C and C++ 7 06-15-2008 04:04 PM
Constructor and Servlet Config kannappanr Java 0 02-26-2008 12:56 PM
Constructor and init() pramod.kuber Java 3 11-04-2007 02:42 AM
why i am getting an error while calling a constructor from another constructor raj_java_j2ee Java 4 07-22-2007 03:39 AM


All times are GMT -4. The time now is 06:56 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved