+ 2
Please help me , what is the wrong in this code ??
7 Answers
+ 5
So, lines 4, 28 and 38
Line 4: The method is setNum(sn) not setnum(sn) so you need to fix that
Line 28: You wrote the string is a without quotes so change that line to this: "type is a " + super.toString();
Line 38: If you do not do System.out.println(m.toString()) nothing will actually be printed so add the System.out.println()
+ 6
Nvm cyk , I removed the dups.
Happens sometimes due to connectivity issues, maybe that was the case here.
+ 4
This question shows up 3 times in the Discussion board. Could you please delete the other 2? And I will be taking a look at the code in the meantime āŗ
+ 4
You call the method like this setnum(sn);
but declared it like that:
public void setNum(int sn){
num=sn;
}
Java is case sensitive change the method call to setNum(sn);
Also on the lines where you override the to string method you have too many " " around the return statement.
And you should annotate the toString method with @Override. This is not a must, but encouraged.
+ 4
Suha To remove your question:
Tap on the three dots next to the title > remove.
But it's done for now.
0
class Machine{
private int num ;
public Machine (int sn){
this.setNum(sn);
}
public void setNum(int sn){
num=sn;
}
public int getNum(){
return num;
}
public String toString(){
return "Machine";
}
}
class Mobile extends Machine{
private String type;
public Mobile (int sn , String type) {
super(sn);
setType(type);
}
public void setType(String type){
this.type=type;
}
public String getType(){
return type ;
}
public String toString(){
return ( "This is a" + this.getType());
}
}
public class Program{
public static void main(String[] args) {
Mobile m = new Mobile (2 , "Apple");
System.out.println(m.toString());
}
}
- 1
Sorry , I donāt know how to deal with application