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);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.