+ 2

Pls i dont understand why the last line of my code refuses to load

public class Life { void bark() { System.out.println("Woof-Woof"); } void neigh() { System.out.println("hufff!!"); } void singer() { System.out.println("Kapachumarimarichupako"); } } class Myclass{ public static void main(String []args) { Life dog=new Life(); Life horse=new Life(); Life zlatan=new Life(); dog.bark(); horse.neigh(); singer.zlatan(); //not ibrahimovic pls } } I don't know why the last line refuses to load

29th Jun 2020, 4:08 PM
Osazuwa Lawson
Osazuwa Lawson - avatar
7 Respuestas
+ 2
zlatan is the object and singer is the method but on your last line you have written vice versa
29th Jun 2020, 5:42 PM
Ian Gitonga Mwangi
+ 1
zlatan is not a method, so a call like ...zlatan() cannot work. What did you intent with this line?
29th Jun 2020, 4:18 PM
Sandra Meyer
Sandra Meyer - avatar
+ 1
Maybe you wanted zlatan.singer() ?
29th Jun 2020, 4:19 PM
Sandra Meyer
Sandra Meyer - avatar
+ 1
Sandra Meyer...I was just playing around with it...other lines worked but this one didn't ...So I was confused... But I did everything the same way...So why the difference or does Java choose words?
29th Jun 2020, 4:20 PM
Osazuwa Lawson
Osazuwa Lawson - avatar
+ 1
Thanks very much... I've seen it already...
29th Jun 2020, 4:23 PM
Osazuwa Lawson
Osazuwa Lawson - avatar
+ 1
You're welcome 🙃
29th Jun 2020, 4:23 PM
Sandra Meyer
Sandra Meyer - avatar
0
zlatan is your object. singer is a method of this type. Take a closer look, you did not exactly the same as in the both lines above...
29th Jun 2020, 4:22 PM
Sandra Meyer
Sandra Meyer - avatar