Modified:
| public class One { private String S; private int I; public One (String theS, int
theI) public void ap () |
public class One { private String S; private int I; public One (String theS, int
theI) public void ap () |
public class TwoA
{
private String A1;
private String A2;
private String A3;
private TwoB twob;
public TwoA()
{
twob = new TwoB();
twob.B2 = "white";
A1 = twob.B1;
A2 = twob.B2;
A3 = twob.B3;
}
}public class TwoB
{
public String B1;
public String B2;
public String B3;
public TwoB()
{
B1 = "red";
B2 = "pink";
B3 = "blue";
}
}
| public class TwoA { private String A1; private String A2; private String A3; private TwoB twob; public TwoA() { twob = new TwoB(); twob.B2 = "white"; A1 = twob.getB1(); A2 = twob.getB2(); A3 = twob.getB3(); } } |
public class TwoB { private String B1; private String B2; private String B3; public TwoB() { B1 = "red"; B2 = "pink"; B3 = "blue"; } public String getB1() { return B1; } public String getB2() { return B2; } public String getB3() { return B3; } public void setB2(String s) { B2=s; } } |
| public class TwoA { private String A1; private String A2; private String A3; private TwoB twob; public TwoA() { twob = new TwoB(); twob.setB(2, "white"); A1 = twob.getB(1); A2 = twob.getB(2); A3 = twob.getB(3); } } |
public class TwoB { private ArrayList B = new ArrayList(); public TwoB() { B.add("red"); B.add("pink"); B.add("blue"); } public String getB(int n) { return (String) B.get(n); } public void setB(int n, String s) { B.set(n, s); } } |
public class Three
{
private String S1;
private String S2;
private String S3;public void setS (String theS1,
String theS2,
String theS3)
{
S1 = theS1;
S2 = theS2;
S3 = theS3;
}public String getS (int n)
{
if (n == 0) return S1;
if (n == 1) return S2;
if (n == 2) return S3;
return S1 + S2 + S3;
}
}public class Three
{
Array aL = new ArrayList();public void setS (String theS)
{
aL.add(theS1);
}public String getS (int n) {
return (String) aL.get(n);
}public String getS() {
String result="";
for(int i=0; i<aL.size(); i++)
result = result + (String) aL.get(i);
return result;
}
}