Answer to Question #301940 in Java | JSP | JSF for Sara

Question #301940

Create an array of type comnunitymember

Then create objects of type (employee, student, faculty) by sending the values ​​to the creator of each class

Store these classes in an array and then print these objects with their type specified using the instanceOf . test


1
Expert's answer
2022-02-24T04:23:59-0500
public class Main {
    public static void main(String[] args) {
        CommunityMember[] members = new CommunityMember[3];
        members[0] = new Employee();
        members[1] = new Student();
        members[2] = new Faculty();
        for (int i = 0; i < members.length; i++) {
            System.out.print(members[i] + " ");
            if (members[i] instanceof Employee) {
                System.out.println("Employee");
            } else if (members[i] instanceof Student) {
                System.out.println("Student");
            } else if (members[i] instanceof Faculty) {
                System.out.println("Faculty");
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS