Question: [SB 3] Is it a good idea to minimize dependencies in classes? If so, why? [SB 4] Consider the following classes: public class Employee {...}

[SB 3] Is it a good idea to minimize dependencies in classes? If so, why?

[SB 4] Consider the following classes:

public class Employee {...}

public class Manager extends Employee {...}

public class Contractor extends Employee {...}

Which of the following would be legal statements?

1. Employee e = new Manager();

2. Manager m = new Contractor();

3. Employee e = new Contractor();

4. Manager m = new Employee();

5. Contractor c = new Employee();

6. Contractor c = new Contractor();

[SB 6] Assuming that the following classes have been defined:

public class Fish extends Pet {

public void method1() {

System.out.println("Fish 1");

super.method2();

}

public void method2() {

System.out.println("Fish 2");

}

}

public class Animal {

public void method2() {

System.out.println("Animal");

}

}

public class Goldfish extends Fish {

public void method2() {

System.out.println("Goldfish 2");

}

}

public class Pet extends Animal {

public void method3() {

System.out.println("Pet 3");

method2();

}

}

And assuming the following variables have been defined:

Pet var1 = new Goldfish();

Animal var2 = new Animal();

Animal var3 = new Pet();

Object var4 = new Fish();

Pet var5 = new Fish();

Fish var6 = new Goldfish();

For each statement below, indicate the output it produces. Be sure to label each output with the numbered statement it corresponds with. If there any errors, please indicate those as well.

1) var1.method2(); 
2) var2.method2(); 
3) var3.method2(); 
4) var4.method2(); 
5) var5.method2(); 
6) var6.method2(); 
7) var1.method3(); 
8) var2.method3(); 
9) var3.method3(); 
10) var4.method3(); 
11) var5.method3(); 
12) var6.method3(); 
13) ((Goldfish)var5).method1(); 
14) ((Pet)var3).method3(); 
15) ((Pet)var4).method1(); 
16) ((Goldfish)var1).method1(); 
17) ((Fish)var4).method1(); 
18) ((Pet)var2).method3(); 
19) ((Goldfish)var5).method1(); 
20) ((Animal)var4).method2(); 

[SB 7] What are the issues with this code?

interface MyInterface {

private double width;

private double height;

public static void printWidth();

public static void printHeight();

}

class C implements MyInterface {

public static void printWidth() {

System.out.println("the width is: " + width);

}

public static void main(String arg[]) {

MyInterface myint = new C();

myint.printDepth();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!