Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1- What is the output of the following program? Why? public class Player { private int lives; public Player() { lives = 0; } public

1- What is the output of the following program? Why?

public class Player { private int lives;

public Player() { lives = 0; }

public Player(int plives) { lives = plives; }

public void addLives() { lives++; }

public void display() { System.out.print(lives + " "); } }

public class SpecialPlayer extends Player {

public SpecialPlayer(int plives) {super(2*plives); } }

public class Main{ public static void main(String[]args){

Player player = new Player(5);

Player special = new SpecialPlayer(5);

player.display()

player.addLives();

player.display();

special.display();

special.addLives();

special.display();

}}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What are four types of SBUs, and what are the goals of each?

Answered: 1 week ago

Question

How was your life influenced by those events?

Answered: 1 week ago

Question

Which of these influenced your life most dramatically?

Answered: 1 week ago