Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is need of declaring a method of a class (having default access) as public ?

 
Prashanth Patha
Ranch Hand
Posts: 62
Eclipse IDE Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if we have a class as follows :

class A // default access
{

public void print() // public method
{
// some code
}

}

Here class A is having default access and the method print() of it is having public declaration. Is there any meaning to this?

 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The class can have a public subclass in the same package, and the inherited method can then be accessed from outside the package. Quick example (each class in its own file)If the method is given default access (by removing the public keyword) that won't compile.
 
Prashanth Patha
Ranch Hand
Posts: 62
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you...

you gave me a nice explanation.
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:The class can ... won't compile.


Thanks for the nice explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic