Csci31 Exercises
Csci31 Exercises
Csci31 Exercises
1.
Page 1
Output:
public class A {
int a = 100;
public A() {
System.out.println("in the constructor of class A: ");
System.out.println("a = "+a);
a = 333;
System.out.println("a = "+a);
}
public void setA( int value) {
a = value;
}
public int getA() {
return a;
}
} //class A
public class B {
double b = 123.45;
public B() {
Sys
}
} //class B
Page 2
Output:
public class A {
int a = 100;
public A() {
System.out.println("in the constructor of class A: ");
System.out.println("a = "+a);
a = 333;
System.out.println("a = "+a);
}
public void setA( int value) {
a = value;
}
public int getA() {
return a;
}
} //class A
public class B extends A {
double b = 123.45;
public B() {
System.out.println("-----in the constructor of class B: ");
System.out.println("b = "+b);
b = 3.14159;
System.out.println("b = "+b);
}
public void setB( double value) {
b = value;
}
public double getB() {
return b;
}
} //class B
Page 3
Page 4
Output:
Page 6
Output:
Page 7
Page 8
Person
- lastName: String
- firstName: String
- father: Person
- mother: Person
+ setLastName(String)
+ getLastName( ): String
.
.
.
Child
- guardian: Person
- age: int
- height: int
- weight: double
+ setGuardian(Person)
+ getGuardian( ): Person
.
.
.
Page 9
Page 10