File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

protected

 
amrit singh
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package points;
class Point{
protected int x,y;
}
what does following lines means:
The fields x and y are declared protected and are accessible outside the package points only in subclasses of class
Point, and only when they are fields of objects that are being implemented by the code that is accessing them.
pls explain protected access moifier
when applied to methods,fields and constructor
thanxxxxxx
 
sunil choudhary
Ranch Hand
Posts: 141
Java Redhat Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


http://www.javaranch.com/ubb/Forum24/HTML/007189.html
Hi Amrit look at the following code
compile it using
javac points\*.java
and then run it by
java points.fultu
(remember to put the whole file in a new dir called points
if you make another class in some other package and try to access variables x and y you will not be able to do that.
however inside the class or to the classses which extend this class the variables are available .
YOu can look at any book for more examples.I am sure there are plenty of them.

package points;
class Point{
protected int x=1,y=2;
System.out.println(x);
System.out.println(y);
}
class fultu extends Point{
public static void main(String args[]){
Point p=new Point();
System.out.println(p.x);
System.out.println(p.y);
}
}
HTH
Sunil
-------------
 
Jane Griscti
Ranch Hand
Posts: 3141
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amrit,
Take a look at this earlier discussion http://www.javaranch.com/ubb/Forum24/HTML/005221.html.
Hope it helps.
Jane
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic