• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

constructor in java ???

 
awshal java
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like the problem is with the instructor, not the constructor.

 
Scott Selikoff
author
Saloon Keeper
Posts: 4010
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stuart Ash:
Looks like the problem is with the instructor, not the constructor.



Awful... just awful...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic