Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class player { private String s1; protected Object shape; player(){ } public Object getShape() { return shape; } // not good practise to allow

public class player {

private String s1;

protected Object shape;

player(){

}

public Object getShape() {

return shape;

}

// not good practise to allow other client classes

// to change the player's character

// a good practise is to protect this method as private

// only itself can change the player character

private void setShape(Object shape) {

this.shape = shape;

}

// intialize a player with a character representing it

public player(Object playerchar) {

super();

this.shape = playerchar;

}

}

public class HumanPlayer extends player {

HumanPlayer(){

super();

}

HumanPlayer(Object shape){

//super();

this.shape = shape;

}

@Override

public void play(TicTacToeBoard ttcb) {

super.play(ttcb);

}

}

Question 1: Did HumanPlayer inherit all of players attributes and methods, including constructors? What are the access modifiers for the inherited methods and attributes?

Question 2: HumanPlayer ahp = new HumanPlayer(); ahp.play(); which method is called?

Question 3: How does HumanPlayer call players constructor?

Question about polymorphism

Polymorphism - Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.

Which one is polymorphism, and which one is not?

class Window {

public void open() {

}

}

class ScrollableWindow extends Window {

@Override

public void open(){

}

}

class DialogWindow extends Window {

@Override

public void open(){

}

}

Question: which open functions were called?

Window sw = new ScrollableWindow();

sw.open();

Window dw = new DialogWindow();

dw.open();

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

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions