URGENT: PLEASE ADD THE NEEDED CODE IN THE BOLDED SECTION IN THE MAIN METHOD. Com
ID: 3916997 • Letter: U
Question
URGENT: PLEASE ADD THE NEEDED CODE IN THE BOLDED SECTION IN THE MAIN METHOD.
Complete the following main method, where one Pacman object and two Ghost objects need to be created. Then, move()methods of the objects will be invoked.
public class PacmanObject {
public void move() {
System.out.println("PacmanObject:Move()");
}
}
public class Ghost extends PacmanObject {
public void move() {
super.move();
System.out.println("Ghost:Move()");
}
}
public class Pacman extends PacmanObject {
public void move(){
super.move();
System.out.println("Pacman::Move()");
}
public static void main(String[] args) {
//one pacman and two Ghosts
PacmanObject[] objs = new PacmanObject[3];
//Write code here so that the output becomes below
//...........
for int(i = 0; i < obj.length; i++)
objs[i].move();
}
}
AFTER ADDING CODE, THE EXPECTED OUTPUT SHOULD BE AS FOLLOWS:
PacmanObject:Move()
Pacman::Move()
PacmanObject:Move()
Ghost:Move()
PacmanObject:Move()
Ghost:Move()
Explanation / Answer
public static void main(String[] args) { //one pacman and two Ghosts PacmanObject[] objs = new PacmanObject[3]; //Write code here so that the output becomes below objs[0] = new Pacman(); objs[1] = new Ghost(); objs[2] = new Ghost(); //........... for (int i = 0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.