This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

protected  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read one book.It said that keyword "protected" is protected by inheritance and package.Does that mean just in the same package or has inheritance relation can use protected methods or variables?

package1--class A has protected static int p1;protected static p2();protected p3();
package2--class D extends A{
A a=new A();
a.p1=1;
a.p2();
A.p2();
a.p3();
}

D is inherited A,but it still has error in "a.p1=1;" and "a.p3();".
Where is my opinion wrong?
Appreciate your kindness.
[ June 14, 2004: Message edited by: E Lan ]
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Protected means that the variable/method/etc in question can be accessed by other classes in the same package, and classes outside the package through inheritance. This means that if Class A extends Class B (in another package), Class A can access any of B's protected members through inheritance (that is, it can access them as if they were its own members / overwrite methods, etc) it cannot access them through dot notation:


At least, thats the way I understand it. If anyone can help clarify this point a little better, I'd appreciate it.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!