3rd May 2018, 8:28 PM
Suha
7 odpowiedzi
+ 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()
3rd May 2018, 8:36 PM
cyk
cyk - avatar
+ 6
Nvm cyk , I removed the dups. Happens sometimes due to connectivity issues, maybe that was the case here.
3rd May 2018, 8:40 PM
Tashi N
Tashi N - avatar
+ 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 ☺
3rd May 2018, 8:30 PM
cyk
cyk - avatar
+ 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.
3rd May 2018, 8:36 PM
Tashi N
Tashi N - avatar
+ 4
Suha To remove your question: Tap on the three dots next to the title > remove. But it's done for now.
3rd May 2018, 8:41 PM
Tashi N
Tashi N - avatar
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()); } }
11th May 2018, 4:57 AM
Павел Сахаревич
Павел Сахаревич - avatar
- 1
Sorry , I don’t know how to deal with application
3rd May 2018, 8:38 PM
Suha