Object as a Reference into Object's Class
Basically I have:
A main class:
Code java:
public class mainClass
{
public static void main(String[] args)
{
extraClass First=new extraClass("First",1,true);
extraClass Second=new extraClass("Second",2,true);
extraClass Third=new extraClass("Third",3,false);
extraClass.compareObjects(First,Second);
}
}
And an extraClass:
Code java:
public class extraClass
{
private String objectName;
private int objectID;
private Boolean isUsed;
public extraClass(String tempName,int tempID,Boolean tempUsed)
{
objectName=tempName;
objectID=tempID;
isUsed=tempUsed;
}
public static void compareObjects(extraClass objectOne,extraClass objectTwo)
{
if (((objectOne.objectName.equalsIgnoreCase("First")&&(objectTwo.objectName.equalsIgnoreCase("Second"))) || (objectOne.objectName.equalsIgnoreCase("Second"))&&(objectTwo.objectName.equalsIgnoreCase("First"))) && (!Third.checkUsed))
{
Third.setUsed(Third);
System.out.println("Yeah");
}
}
public Boolean checkUsed(extraClass tempName)
{
if (tempName.isUsed)
return true;
else
return false;
}
public void setUsed(extraClass tempName)
{
tempName.isUsed=true;
}
}
I'm given the errors:
Quote:
cannot find symbol variable Third
cannot find symbol variable Third
cannot find symbol variable Third
The problem is in the compareObjects method in the extraClass when I attempt to use an object I created in the mainClass using the extraClass.
Any ideas?
Re: Object as a Reference into Object's Class
Code :
&& (!Third.checkUsed))
Third.setUsed(Third);
You invoke methods on Third, which hasn't been declared anywhere in your 'extraClass' Class.
Not sure what you're trying to do with 'Third' in extraClass. I'm no expert by a long shot, but I got a feeling what you're thinking of doing isn't possible.
Also it would be a good idea to stick to the convention of starting class names with capital letters and variables with lower case, so for your example, "ExtraClass" and variables as follow's "aVariable"
Either way, good luck.
Re: Object as a Reference into Object's Class
Quote:
Originally Posted by
newbie
Code :
&& (!Third.checkUsed))
Third.setUsed(Third);
You invoke methods on Third, which hasn't been declared anywhere in your 'extraClass' Class.
Not sure what you're trying to do with 'Third' in extraClass. I'm no expert by a long shot, but I got a feeling what you're thinking of doing isn't possible.
Also it would be a good idea to stick to the convention of starting class names with capital letters and variables with lower case, so for your example, "ExtraClass" and variables as follow's "aVariable"
Either way, good luck.
The Third object was declared and initialized in the Main class.
Re: Object as a Reference into Object's Class
Well yeah, but it has no reference within "extraClass", its an instance of extraClass.
Re: Object as a Reference into Object's Class
Quote:
Originally Posted by
newbie
Well yeah, but it has no reference within "extraClass", its an instance of extraClass.
Alright that's where I'm lost. How can I either get extraClass to 'see' Third, or possibly accomplish the same goal in a different way?
Re: Object as a Reference into Object's Class
Well firstly, state you're design specification, what are you trying to accomplish?
Also is there a reason you are trying invoke a Boolean variable isUsed? i.e, its not a method.
Re: Object as a Reference into Object's Class
This is a small part of a project I've started on, but what I'm trying to accomplish with this example code is combine different objects to create a new object. This will be used in a simple DOS era alchemy type of game.