+ 1

why the last statement is gaaving me an Error

package day_4; //Program to illustrate the concept of inheritance class Shadow { // the Shadow class has two fields public int breed; public int age; // the Shadow class has one constructor public Shadow(int breed, int age) { this.breed = breed; this.age = age; } // the Shadow class has three methods public void trainHello(int decrement) { age -= decrement; } public void trainSit(int increment) { age+= increment; } // toString() method to print info of Shadow public String toString() { return("Breed of shadow "+breed +"\n" + "age of shadow is "+age); } } //derived class class Medicine extends Shadow { // the Medicine subclass adds one more field public int forFur; // the Medicine subclass has one constructor public Medicine(int breed,int age, int presentFur) { // invoking base-class(Shadow) constructor super(breed , age); forFur = presentFur; } // the Medicine subclass adds one more method public void setMedicine(int newValue) { forFur = newValue; } // overriding toString() method @Override public String toString() { return (super.toString()+ "\nseat Medicine is "+forFur); } } //driver class public class demo { public static void main(String args[]) { Medicine mb = new Medicine(3, 100, 25); System.out.println(mb.toString()); Shadow mm= new Shadow(4,10)

8th Aug 2018, 2:15 PM
Christy Alex
Christy Alex - avatar
9 Answers
0
in the function tostring when returning the string you did this wrong: "Breed of shadow" + breed .... you can't add up string and int. you must convert is to string first, plus you forgot to use this
8th Aug 2018, 2:33 PM
Tomer Sim
Tomer Sim - avatar
0
you must convert the int to string
8th Aug 2018, 2:33 PM
Tomer Sim
Tomer Sim - avatar
0
the problem is only with the last line of code shadow mm= new Shadow(4,10);
8th Aug 2018, 2:51 PM
Christy Alex
Christy Alex - avatar
0
others r oky
8th Aug 2018, 2:52 PM
Christy Alex
Christy Alex - avatar
0
did the program run when you deleted the last line?
8th Aug 2018, 2:54 PM
Tomer Sim
Tomer Sim - avatar
0
yes
8th Aug 2018, 3:02 PM
Christy Alex
Christy Alex - avatar
0
perfectly !
8th Aug 2018, 3:02 PM
Christy Alex
Christy Alex - avatar
0
oh there is aomething wrong !
8th Aug 2018, 3:04 PM
Christy Alex
Christy Alex - avatar
0
you're very confusing
8th Aug 2018, 10:00 PM
Tomer Sim
Tomer Sim - avatar