aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is need of declaring a method of a class (having default access) as public ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "what is need of declaring a method of a class (having default access) as public ?" Watch "what is need of declaring a method of a class (having default access) as public ?" New topic
Author

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

Prashanth Patha
Ranch Hand

Joined: May 06, 2011
Posts: 56
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?


Thanks & Regards
_______________
Prashanth

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4167
    
    3

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.


luck, db
There are no new questions, but there may be new answers.
Prashanth Patha
Ranch Hand

Joined: May 06, 2011
Posts: 56
Thank you...

you gave me a nice explanation.
Rahul Sudip Bose
Ranch Hand

Joined: Jan 21, 2011
Posts: 637

Darryl Burke wrote:The class can ... won't compile.


Thanks for the nice explanation.


SCJP 6. Learning more now.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: what is need of declaring a method of a class (having default access) as public ?
 
Similar Threads
Doubt in accessing a method
abstract nature with package level access?
accessability of outerclass members in inner class !!!
Query on Overriding
Access control