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.
  1. B b = new B();
  2. B b = new C();
  3. D d = new D();
  4. C c = new D();
  5. B b = new D();
  6. G g = new E();
  7. E e = new G();
  8. E e = new F();
  9. B b = new G();
    D d = new D();
    d = b;
  10. 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.
  1. B b = new B(); Not permissible because B is an interface and cannot be instantiated
  2. B b = new C(); Not permissible because C is abstract and cannot be instantiated
  3. D d = new D(); Permissible
  4. C c = new D(); Permissible
  5. B b = new D(); Permissible
  6. G g = new E(); Not permissible because of incompatible types (an E is not a G)
  7. E e = new G(); Permissible
  8. E e = new F(); Not permissible because of incompatible types (an F is not an E)
  9. B b = new G();
    D d = new D();
    d = b;
    Not permissible because of incompatible types (a G is not a D)
  10. B b = new G();
    D d = new D();
    b = d;
    Permissible