• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

need a hand to understand the code  RSS feed

 
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
 
Ranch Hand
Posts: 2410
  • 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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!