Question 1
In the code below, the bodies of the methods are not important, so they
have been omitted. Draw a class diagram depicting all
classes and interfaces and their relationships. Include methods only where
necessary.
public interface MyType
{
void method1();
void method2();
}
public abstract class AbstractType implements MyType
{
public void method1() {. . .}
public void method2() {. . .}
public void method3() {. . .}
public abstract void method4();
}
public class ConcreteType extends AbstractType
{
public void method4() {. . .}
}
public class AnotherClass
{
private MyType[] anArray;
public void method5() {. . .}
}
public class YetAnotherClass
{
public AnotherClass method6() {. . .}
}
|
In the code below, the bodies of the methods are not important, so they
have been omitted. Draw a class diagram depicting all
classes and interfaces and their relationships. Include methods only where
necessary.
public interface MyType
{
void method1();
void method2();
}
public abstract class AbstractType implements MyType
{
public void method1() {. . .}
public void method2() {. . .}
public void method3() {. . .}
public abstract void method4();
}
public class ConcreteType extends AbstractType
{
public void method4() {. . .}
}
public class AnotherClass
{
private MyType[] anArray;
public void method5() {. . .}
}
public class YetAnotherClass
{
public AnotherClass method6() {. . .}
}
|
|
Consider the class diagram below. For each of the assignments on the right, indicate
whether it is permissible. If it is not permissible, indicate why not.
|
- B b = new B();
- B b = new C();
- D d = new D();
- C c = new D();
- B b = new D();
- G g = new E();
- E e = new G();
- E e = new F();
- B b = new G();
D d = new D();
d = b;
- B b = new G();
D d = new D();
b = d;
|
Consider the class diagram below. For each of the assignments on the right, indicate
whether it is permissible. If it is not permissible, indicate why not.
|
- B b = new B();
Not permissible because B is an interface and cannot be
instantiated
- B b = new C();
Not permissible because C is abstract and cannot be
instantiated
- D d = new D();
Permissible
- C c = new D();
Permissible
- B b = new D();
Permissible
- G g = new E();
Not permissible because of incompatible types
(an E is not a G)
- E e = new G();
Permissible
- E e = new F();
Not permissible because of incompatible types
(an F is not an E)
- B b = new G();
D d = new D();
d = b;
Not permissible because of incompatible types
(a G is not a D)
- B b = new G();
D d = new D();
b = d;
Permissible
|