• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Access Modifiers

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Zoo
{
public String coolMethod(){
return "Wow baby";
}
}

class Moo
{
public void useAZoo(){
Zoo z=new Zoo();
//If the preceding line complies Moo has access the Zoo class.
//But... does it have access to coolMethod()?
System.out.println("A Zoo says " +z.coolMethod());
//the preceding line works because Moo can access the public method
}
}
i have complied this code and when running the program it exception java.lang.NoSuchMethodError:main
this examples is from K&B page no 25
there is point, "whether method code in one class can access a member of another class"
please guide me for the above code.

thank you,
trupti.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy!


java.lang.NoSuchMethodError:main


Your problem has nothing to do with access.
When you want to run a program by typing java Moo then Moo has to have a main method.


Yours,
Bu.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you please tell me what is the file name
it its Moo.java then it must be public
only one public class can be exist in a single file
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If there is one public class in a file then the file name must be the name of the class.
If there is no public class in a file then the file name can be any.
There cannot be more than one public class in one file.


Bu.
 
Wanna see my flashlight? How about this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic