+ 2

What is wrong with this code?Abstract classe boar game attributes java

class Main { public static void main(String[] args) { //do not touch this code Monopoly monopoly = new Monopoly(); Chess chess = new Chess(); Battleships battleships = new Battleships(); monopoly.play(); chess.play(); battleships.play(); } } abstract class Game { abstract String getName(); abstract void play(); } class Monopoly extends Game { //give "Monopoly" name to game String getName() { return monopoly; } // play method should print "Buy all property." void play() { System.out.println("Buy all property"); } } class Chess extends Game { //give "Chess" name to game String getName() { return chess; } // play method should print "Kill the enemy king" void play() { System.out.println("Kill the enemy king"); } } class Battleships extends Game { //give "Battleships" name to game String getName() { return battleships; } // play method should print "Sink all ships" void play() { System.out.println("Sink all ships"); } }

22nd Feb 2022, 9:09 AM
ĐĄĐŸŃ„Ń–Ń брясĐșĐŸ
5 Answers
+ 5
package html; class Main { public static void main(String[] args) { //do not touch this code Monopoly monopoly = new Monopoly(); Chess chess = new Chess(); Battleships battleships = new Battleships(); monopoly.play(); chess.play(); battleships.play(); } } abstract class Game { abstract String getName(); abstract void play(); } class Monopoly extends Game { //give "Monopoly" name to game String getName() { return "monopoly"; } // play method should print "Buy all property." void play() { System.out.println("Buy all property."); } } class Chess extends Game { //give "Chess" name to game String getName() { return "chess"; } // play method should print "Kill the enemy king" void play() { System.out.println("Kill the enemy king."); } } class Battleships extends Game { //give "Battleships" name to game String getName() { return "battleships"; } // play method should print "Sink all ships" void play() { System.out.println("Sink all ships."); } } //100%
30th May 2022, 3:09 PM
Javohir
Javohir - avatar
+ 4
class Main { public static void main(String[] args) { //do not touch this code Monopoly monopoly = new Monopoly(); Chess chess = new Chess(); Battleships battleships = new Battleships(); monopoly.play(); chess.play(); battleships.play(); } } abstract class Game { abstract String getName(); abstract void play(); } class Monopoly extends Game { //give "Monopoly" name to game String getName() { return "monopoly"; } // play method should print "Buy all property." void play() { System.out.println("Buy all property"); } } class Chess extends Game { //give "Chess" name to game String getName() { return "chess"; } // play method should print "Kill the enemy king" void play() { System.out.println("Kill the enemy king"); } } class Battleships extends Game { //give "Battleships" name to game String getName() { return "battleships"; } // play method should print "Sink all ships" void play() { System.out.println("Sink all ships"); } }
9th May 2022, 5:36 AM
A MOHAMED- S92083203- 121643203
A MOHAMED- S92083203-  121643203 - avatar
+ 1
class Main { public static void main(String[] args) { //do not touch this code Monopoly monopoly = new Monopoly(); Chess chess = new Chess(); Battleships battleships = new Battleships(); monopoly.play(); chess.play(); battleships.play(); } } abstract class Game { abstract String getName(); abstract void play(); } class Monopoly extends Game { //give "Monopoly" name to game String getName() { return "monopoly"; } // play method should print "Buy all property." void play() { System.out.println("Buy all property."); } } class Chess extends Game { //give "Chess" name to game String getName() { return "chess"; } // play method should print "Kill the enemy king" void play() { System.out.println("Kill the enemy king."); } } class Battleships extends Game { //give "Battleships" name to game String getName() { return "battleships"; } // play method should print "Sink all ships" void play() { System.out.println("Sink all ships."); } }
16th Nov 2022, 6:32 PM
Guy Martial KEYOU
+ 1
//you need to add public String name inside abstract class game{} abstract class Game { public String name; abstract String getName(); abstract void play(); }
25th Jul 2023, 5:24 PM
Dhanuji S Ranasinghe
Dhanuji S Ranasinghe - avatar
0
Make all of the getName() return values as String. String getName() { return "monopoly"; } String getName() { return "chess"; } String getName() { return "battleships"; }
22nd Feb 2022, 9:27 AM
Avinesh
Avinesh - avatar