5/ 27 Lab Object Variables
public class ClassParameterDemo
{
public static void main(String[] args)
{
// ToyClass anObject = new ToyClass("Mr. Cellophane", 0);
ToyClass aObject = new ToyClass("Mrs. Smith",1);
ToyClass bObject = new ToyClass("Mrs. Smith",1);
ToyClass cObject ;
cObject = aObject ;
if (aObject == bObject)
System.out.println("a to b same reference");
else
System.out.println("a to b not same reference");
if (aObject.equals(bObject))
System.out.println("a to b same constant");
else
System.out.println("a to b not same constant");
if (aObject == cObject)
System.out.println("a to c same reference");
else
System.out.println("a to c not same reference");
if (aObject.equals(cObject))
System.out.println("a to c same constant");
else
System.out.println("a to c not same constant");
// System.out.println(anObject);
// System.out.println(aObject);
// System.out.println(
// "Now we call changer with anObject as argument.");
// ToyClass.changer(anObject);
// System.out.println(anObject);
}
}
{
public static void main(String[] args)
{
// ToyClass anObject = new ToyClass("Mr. Cellophane", 0);
ToyClass aObject = new ToyClass("Mrs. Smith",1);
ToyClass bObject = new ToyClass("Mrs. Smith",1);
ToyClass cObject ;
cObject = aObject ;
if (aObject == bObject)
System.out.println("a to b same reference");
else
System.out.println("a to b not same reference");
if (aObject.equals(bObject))
System.out.println("a to b same constant");
else
System.out.println("a to b not same constant");
if (aObject == cObject)
System.out.println("a to c same reference");
else
System.out.println("a to c not same reference");
if (aObject.equals(cObject))
System.out.println("a to c same constant");
else
System.out.println("a to c not same constant");
// System.out.println(anObject);
// System.out.println(aObject);
// System.out.println(
// "Now we call changer with anObject as argument.");
// ToyClass.changer(anObject);
// System.out.println(anObject);
}
}
0 Comments:
Post a Comment
<< Home