A private variable or method may be used only by an instance of the class. : private « Modifiers « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Modifiers » private 
3.2.2.A private variable or method may be used only by an instance of the class.
class Complex {
   private double real,  imaginary;

 public Complex(double r, double i) {
   real = r; imaginary = i;
 }
 public Complex add(Complex c) {
   return new Complex(real + c.real,
   imaginary + c.imaginary);
 }
}

public class MainClass{
   public static void main(String[] argv) {
     Complex c1 = new Complex(12);
     Complex c2 = new Complex(34);
     Complex c3 = c1.add(c2);
     //double d = c3.real; // Illegal!
   }
 }
3.2.private
3.2.1.private members can be accessed only by code in the same class.
3.2.2.A private variable or method may be used only by an instance of the class.
3.2.3.An instance of a subclass is denied access for private features
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.