Results 1 to 8 of 8
Thread: Access Specifiers
- 03-17-2011, 05:19 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 5
- Rep Power
- 0
- 03-17-2011, 05:23 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,068
- Blog Entries
- 3
- Rep Power
- 15
You can not directly access private variables. As for protected and public I will let you test that, switch a to protected then try modifying it directly in main, then compile and run it and see what happens. Try the same thing with public.
- 03-17-2011, 05:55 AM #3
And/or read all about access and declaration modifiers:
Names
db
- 03-17-2011, 06:07 AM #4
Member
- Join Date
- Mar 2011
- Posts
- 1
- Rep Power
- 0
U cant
since the data member is private it uses to access only within the methods of that class only,though the object of that class is created in another class.
- 03-17-2011, 09:19 AM #5
Member
- Join Date
- Mar 2011
- Location
- Bangalore, India
- Posts
- 5
- Rep Power
- 0
Private members of a class cannot be accessed by anybody.
Next level of abstraction is Protected. This means, all the classes derived from the current class can access thr variable as public.
The last level is Public. Anybody can access public members.
- 03-17-2011, 09:46 AM #6
Member
- Join Date
- Mar 2011
- Posts
- 5
- Rep Power
- 0
thanx.
for all answers.
But Can u tell with an example?????
- 03-17-2011, 09:48 AM #7
Member
- Join Date
- Mar 2011
- Posts
- 5
- Rep Power
- 0
thanx.
for all answers.
But Can u tell with an example?????
- 03-17-2011, 09:54 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Your original example is a bit misleading because your main( ... ) method is defined in that class itself so it has all access rights to any member, even if it is private. For an experiment: define your main( ... ) method in another class and see for yourself.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
Similar Threads
-
Difference Between Access Specifiers & Access Modifiers
By ujjwal in forum New To JavaReplies: 0Last Post: 01-10-2011, 06:26 AM -
Format Specifiers
By Cass29 in forum New To JavaReplies: 3Last Post: 12-20-2009, 03:49 PM -
Default Access (package access) confusion
By gauravrajbehl in forum New To JavaReplies: 1Last Post: 11-18-2009, 10:48 AM -
Method access or field access
By carderne in forum New To JavaReplies: 2Last Post: 12-06-2008, 06:20 PM -
Help with access a database using Microsoft Access
By cachi in forum JDBCReplies: 1Last Post: 08-07-2007, 07:51 AM
Bookmarks