• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

too much simple question: call public method

 
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Error:

can not find symbol

Problem is about this.displayGreeting(); and z.displayGreeting();
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both those lines try to call the displayGreeting() method on an object of class s (by the way, don't use lower case letters for class names - especially single letters! - as it makes it harder to read). But that class doesn't gave that method.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I define displayGreeting(); method so it can be acessed from any where?( other than static)
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your displayGreeting() method is accessible from anywhere. But it belongs to the Outer class. Which means you can only call it on an instance of an Outer object. You can't then just call it on any old object.

In object-oriented programming you'll often see interactions between objects described as "sending messages". One object sends a message to another object, which replies. The messages you can send to an object correspond to the methods that object has.

In this case, you're trying to send a message to an object that doesn't understand it. You can tell a dog to bark, you can't tell a daffodil to!
 
Do you want ants? Because that's how you get ants. And a tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic