IC211 Spring AY 2020

HW Inheritance

Name (Last, First): ____________________________________________________ Alpha: _____________________
Describe help received: _________________________________________________________________

  1. [52Pts] Consider class Bar derived from class Foo as shown below:
    Foo.java Bar.java HWa.java
    public class Foo {
    
      public void func1(int x) {
        System.out.println("my F1");
      }
      public static void func2(char c) {
        System.out.println("my F2");
      }
      public void func3() {
        System.out.println("my F3");
      }
      public void func4() {
        System.out.println("my F4");
      }
    }
    public class Bar extends Foo {
    
      public void func1(int x) {
        System.out.println("my B1");
      }
      public void func2(double d) {
        System.out.println("my B2");
      }
      public static void func5() {
        System.out.println("my B5");
      }
      public void func4() {
        System.out.println("my B4");
      }
    }
    
    
                  
    public class HWa {
    
      public static void
        main(String[] args) {
        Foo f = new Foo();
        Bar b = new Bar();
    
        // HERE!
      }
    }
    
        

    Consider each expression below as appearing at the HERE! in file HWa.java, and write either "error" if the expression won't compile, or write the output that the resulting function call would produce.

    1. f.func1(38)  ______
    2. b.func1(38)  ______
    3. f.func2('A') ______
    4. b.func2('A') ______
    1. f.func2(1.8) ______
    2. b.func2(1.8) ______
    3. f.func3()    ______
    1. b.func3()    ______
    2. func4()      ______
    3. Foo.func4()  ______
    1. f.func5()    ______
    2. b.func5()    ______
    3. Bar.func5()  ______
  2. [48Pts] Complete AcMid so that the following code produces the output: 172234 Poe SCS
    AcMid m = new AcMid("Poe","172234","SCS");
    System.out.println(m.toString());
    Mid.java AcMid.java
    public class Mid {
      private String last;
      private String alpha;
    
      public Mid(String ln, String al) {
        last = ln;
        alpha = al;
      }
      public String toString() {
        return alpha + " " + last;
      }
      public String getAlpha() {
        return alpha;
      }
      public String getLast() {
        return last;
      }
    }
    public class AcMid extends Mid {
      private String major;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    }