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

need a hand to understand the code  RSS feed

 
Dana Horst
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,I apologize forehead if i ask silly questions.

I have two classes, class Pet and PetMaster. I have a few quiestions what means what, please look at comments :






as a result, i get :

I’m so hungry…let me have a snack like nachos!
OK!! OK!! Tweet!! Tweet!!
Good night, see you tomorrow

Question 1: in the main class i didnt called aWord (i did myPet.say),why then i get such a result? (OK!! OK!! Tweet!! Tweet!!). could you please explain how petReaction connected with method "say" from class Pet?
Question 2: i think the output is what follows System.oupt.println. why do i get output from the myPet.eat();

Thank you!
Dana
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aWord in that method is what is called a formal parameter. When the method is called, you send a corresponding actual parameter, whose value gets copied into aWord. aWord can then be used in the method.

The reason you get output when you call myPet.eat() is that method contains a System.out.println statement.
 
Dana Horst
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brilliant! I got it!Thank you very much!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!