Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Take a look at the following Java program. -------------------------------------

ID: 3870375 • Letter: T

Question

Take a look at the following Java program.

---------------------------------------------------------------------------------------------

interface person {

abstrcat public void whoami();
}

abstract class Employee implements person {

int age;
}

class Staff extends Employee {

int overtime;

public void whoami() {
System.out.println("asd");
}
}

class Faculty extends Employee {

String research;

public void whoami() {
System.out.println("dsa");
}
}

public class Question6


static void print(Object[] a){
// missing code
}
public class abstrcat {

public static void main(String[] args) {
Object[] a = {new Staff(), new Faculty(), new String()};

print(a);

}

}

---------------------------------------------------------------------------------------------

Write the correct missing Java code for the print method which calls whoami for each person in the array.

Explanation / Answer

Please find my code.

public class Question6 {

   static void print(Object[] a){

       // missing code

       for(Object obj : a) {

          

           person p = (person)obj; // type casting

           p.whoami();

       }

   }

   public static void main(String[] args) {

       Object[] a = {new Staff(), new Faculty(), new String()};

       print(a);

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote