• Post Reply Bookmark Topic Watch Topic
  • New Topic

public class  RSS feed

 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the usage of " public class"?

This makes possible to access to class from outside of package, But when it became useful?

( I am taking about top level class, not inner class)

 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find this a weird question. It's useful when you need to use a class which is not in your current package. Which happens all the time.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even If we don't use "public class"

We can use public modifier to use any member of that in public way. Then why do we need "public class"?
 
Smitesh Shinde
Ranch Hand
Posts: 45
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you need an instance of a class to access it's members unless they are static. It's only possible when the class is visible to you. Besides creating an instance class being public makes itself extensible too.

In short public class makes itself reusable which is ultimate goal of the Object Oriented Programming.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!