My Anna

Indias Biggest Engineering Education Community Enriching Students Minds with Latest Placement Papers, Study Materials, Fresher Jobs and Free E Books

A Unit of Aim Clear Technologies Ltd.
Search Study Materials, Jobs, Placement Papers, Interview Tips, Training Videos & More

Advertise with us

Who is online



Post new topic Reply to topic  [ 1 post ] 

mkalaiyarasan
As a Family
As a Family
User avatar

Joined:
Tue Aug 25, 2009 5:25 pm
Beans: 35
In Bank: 0
College: studied
Degree: BE
Department: cse
State: Tamilnadu
Fav Quote: cse
Position: Employee
 
#2
Fri Aug 28, 2009 4:20 pm
Post subject: Objects Post
What is an object?
Create objects with the new keyword followed by a constructor. For example, the following program creates a TwoDPoint object and prints its fields:
class OriginPrinter {

public static void main(String[] args) {

TwoDPoint origin; // only declares, does not allocate

// The constructor allocates and usually initializes the object
origin = new TwoDPoint();

// set the fields
origin.x = 0.0;
origin.y = 0.0;

// print the two-d point
System.out.println(
"The origin is at " + origin.x + ", " + origin.y);

} // end main

} // end OriginPrinter
The . is the member access separator.
A constructor invocation with new is required to allocate an object. There is no C++ like static allocation.
To compile this class, put it in a file called OriginPrinter.java in the same directory as TwoDPoint.java and type:
$ javac OriginPrinter.java
What does this produce?
Is this a complete program now? Can you run it?

Profile E-mail
Offline

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 
Bookmark & Share

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB Group.

phpBB SEO