Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Static Methods & 2 Constructors

Status
Not open for further replies.

Wund1

Technical User
Sep 16, 2001
1
US
I have failed. Yes, believe it. I have been unable to generate a static method in constructor#2 to call constructor#1. Any help would be much appreciated. Thank you in advance.

sample code:

public class CardApplet extends Applet
{....
public void init()
{...
class Card
{...
public Card(int posX, int posY, int suit1, int rank1)
{...// Constructor#1

public Card (int X, int Y)
{...//Constructor #2
this("reference to a void function"); X = posX; Y = posY;
 
I don't understand what you want to do. Do you want to call Constructor 1 from Constructor 2? If so then the problem is that the constructor you are calling does not exist. Look at the signature for the method you are calling in Constructor 2: it accepts one String parameter. The actual Constructor 1 accepts four int parameters.

Here is an example of calling Constructor 1 from Constructor 2:
Code:
public class CardApplet extends Applet {
   
public void init() {
   /* Blah, Blah, Blah */
}    

class Card {
   /* Define Constructor 1 */
   public Card(int posX, int posY, int suit1, int rank1) {
      /* Blah, Blah, Blah */
   }

   /* Define Constructor 2 */
   public Card (int X, int Y) {
      /* Call Constructor 1 */
      this(X,Y,0,0); 
   }
}  /* End of class Card */

}  /* End of class CardApplet */
On another note, I don't think you really need an Inner class here and I would suggest defining Card outside of CardApplet incase you need to use this class elsewhere. You are not going to want to pass around a CardApplet object just to use Card. Wushutwist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top