What is the difference between the public access modifier and default access modifier?

Questions by Roshini

Showing Answers 1 - 9 of 9 Answers

Dev Reddy

  • Aug 19th, 2006
 

Hi ,if we declare public access modifier to any variables or Methods in a class, so that here we can access those variables or methods from any class or any subclass of any class and from any package.where as in default access modifier, the access is belong to any class or sub class of current pacckage.regards Basa Devareddy

  Was this answer useful?  Yes

Raj Patil

  • Aug 19th, 2006
 

Public-

            When we use public access then we are free to access these methods,class or variable from any other classes it may be in same package or different.

Default-

         when we not specify any access modifier then by default is Default.

It is access only in package level

  Was this answer useful?  Yes

murugeswari

  • Aug 23rd, 2006
 

Hi friends, In java , using public access modifier,variables and methods can be accessed by other classes. But defualt access modifier is private,So methods and variables can't accessed by other classes.

  Was this answer useful?  Yes

pmachhi

  • Sep 2nd, 2006
 

i wan to know how does the intializatin of the variables starts fromstaic, private or public till the last one

  Was this answer useful?  Yes

JIGAR

  • Sep 14th, 2006
 

class

public class can be accessed from any other classes... its public to whole java universe...  where as default is package level access... if the sub class is in diff package and is default than it cant be access from other classes out side the package.

instance variables

same thing is here public means can be accessed anywhere in java universe... where as default cant be accessed outta package,,,,

and u know local variable do not have access modifier :)

gotcha ???

  Was this answer useful?  Yes

Santosh N

  • Jun 11th, 2008
 

Any attribute or method with default access modifier can be accessed from other classes or methods only within the same package  whereas any attribute or method with public access modifier can be accessed from anywhere in the application.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions