• Post Reply Bookmark Topic Watch Topic
  • New Topic

A Query about Protected Scope in Java  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

This is a query about visibility of protected variables :





Please let me know why is first.protectedvariable is not possible
 
Rok Štelcer
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Ravi Kiran V wrote:Please let me know why is first.protectedvariable is not possible

Check the following link for answer:
http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html
(Hint: row World)


Regards,
Rok
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What errors are you getting? You don't appear to have complete statements in the code you posted. The errors have probably got nothing to do with protected access.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first.protectedvariable; // Not Ok

As i said this line gives rise to error .

The error is

The field First.protectedvariable is not visible
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran V wrote:first.protectedvariable; // Not Ok

As i said this line gives rise to error .

The error is

The field First.protectedvariable is not visible


See section 6.6.2 of the Java Language Specification.

http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.6.2

Also, you may want to search the ranch for previous discussions about this.

Henry
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey you people are really great . Pointing out to the exact link and where explanation is simple .

A protected member or constructor of an object may be accessed from outside the package in which it is declared only by code that is responsible for the implementation of that object.


This line explains a lot.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I tried it, I got "not a statement" compiler errors. Wonder why . . .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!