Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I call a method for an instance inside System.out.println message?  RSS feed

 
drew taylor
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please can someone tell me how can I call the method inside the System.out.println? I keep getting an error.

Dog bigDog = new Dog();
bigDog.name = "BigDoggy";

System.out.println("BigDoggy says: ") + bigDog.name() ;
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println("BigDoggy says: " + bigDog.name());

Yes, it's that simple. Just put the brackets right.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!