## Quiz 2 (Exercises from Chap. 11)

Figure 1 is meant to show that class A is abstract and that classes
B and C are concrete subclasses. In class A, only method m1 is abstract,
the other two methods are implemented. Both B and C implement method m1.
B overrides m2, and C overrides m3.

Figure 3 shows that Y is a subclass of X. Instance variables of X are
x1 (an int) and name (a String), which you may assume are private.
Y has an extra instance variable called y1 (an int).

- Circle the illegal statements.
- A a ;
- B b ;
- C c ;
- b = new B() ;
- b = new A() ;
- a = new C() ;
- a = new A() ;
- c = new B() ;
- c = new C() ;
- c = b ;
- a = c ;
- a.m1() ;
- b.m1() ;
- c.m1() ;
- c.m2() ;
- c.m3() ;
- b.m3() ;

- Write an equals method for X which indicates that two X objects
are equal if they have the same x1 and name and neither reference is null.
- Write an equals method for Y which indicates that two Y objects
are equal if they have the same x1 and name and y1
and neither reference is null.
- Write a toString method for X which gives a form like

X[x1 = 5, name = xenon]
- Write a toString method for Y which gives a form like

Y[x1 = 5, name = xenon][y1 = 10]