aspose file tools*
The moose likes Beginning Java and the fly likes constructor in java ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "constructor in java ???" Watch "constructor in java ???" New topic
Author

constructor in java ???

awshal java
Greenhorn

Joined: Nov 07, 2005
Posts: 1
idon't know what is the cnstructor is and how can i find it in below
code i have ahome work and i need to understand it plz
the question is


The constructor for Circle has three formal arguments.,write them, how each
of these formal parameters is used when the constructor is called in
statement // 1 of the above program. Your answer must make it clear that
you understand the difference between actual arguments and formal
arguments.

this is the code
import java.io.*;
class TestMirror {
static public void main (String [ ] args) {
Shape form1 = new Circle (10, 10, 5); // 1
Mirror mirror1 = new Mirror (5, form1); // 2
Mirror mirror2 = mirror1; // 3
Shape form2 = new Square (15, 20, 10); // 4
mirror1.setShape (form2); // 5
}
}
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hi, welcome to the ranch!

Sounds like you've been thrown out in the cold by your instructor with no reading references? You'll probably want to find a book like Thinking In Java (free online access!) to help you with fundamentals like this.

A constructor looks almost like a regular method, but it is special. You can spot them because they have no return type and the name is the same as the class. So the constructor for Circle would look something like

public Circle( int this, int that, int other )

I spotted this line in your sample code:

Shape form1 = new Circle (10, 10, 5);

In that line we create a new circle and call the constructor with three int (or other number) arguments. You'll have to look into the Circle class and see if it describes the three arguments. They might be X & Y coordinates and radius ... or not. Let us know what you find!

PS: "this" "that" and "other" are made up place holders for real names. In fact "this" would not be a valid name for a paremeter. Look into the Circle code for the real thing.
[ November 07, 2005: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Stuart Ash
Ranch Hand

Joined: Oct 07, 2005
Posts: 637
Looks like the problem is with the instructor, not the constructor.



ASCII silly question, Get a silly ANSI.
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

Originally posted by Stuart Ash:
Looks like the problem is with the instructor, not the constructor.



Awful... just awful...


My Blog: Down Home Country Coding with Scott Selikoff
 
jQuery in Action, 2nd edition
 
subject: constructor in java ???