• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

main class file

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the difference of writing public or not writing public for the main class ?
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
}
}

OR

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
}
}

What will be the differences in these codes ?
 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello arnab, welcome to the ranch.
using the public keyowrd for a class makes that class visible to every other class in any other package. if you use the public keyword there can only be one public class in one file so this is allowed; saved as A1.java

while not using the public keyword makes it only visible to classes in the same package (this is what's known as default access)
davy
[ February 23, 2004: Message edited by: Davy Kelly ]
 
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic