Accesing the private members between the instance of same class

From: Vijay (vij_singh_at_hotmail.com)
Date: 12/13/04


Date: 13 Dec 2004 04:48:03 -0800

Hi

I don't know if this is language specific, but in java a object can
access the private members of another object which belongs to same
class. Is this the OOP specific, or is this OOD principle.

Following is the example :

public class TestInstance
{
private int v_test1;
private int v_test2;

public static void main(String[] args)
{
TestInstance ts1 = new TestInstance(1, 2);
TestInstance ts2 = new TestInstance(3, 4);

System.out.println("Value of the 1st instance is: "+ ts1.v_test1 +
ts1.v_test2);
System.out.println("Value of the 1st instance is: "+ ts2.v_test1 +
ts2.v_test2);
}

public TestInstance(int x, int y)
{
  v_test1 = x;
  v_test2 = y;
 }
}

Regards
Vijay



Relevant Pages

  • Spurious printing: AWTRenderer, FOP
    ... application rendered FOP XML. ... private static final int intEvenAndAll = 0; ... private int intStartNumber; ... catch (Exception exception) ...
    (comp.lang.java.programmer)
  • Re: Matrix - Transformation
    ... private double x; ... public int BoardNumber ... private void MapMillimetersToPixels(Graphics gfx, Rectangle ... private int MillimetersToPixels_X ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: System.Timers.Timer performance test ?
    ... > Each USer object create a MyTimer object. ... > public delegate void MyTimerHandler; ... > private DateTime startTime, endTime; ... > private int name; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: More adventures in learning OOP
    ... public class Person{ ... private ArrayList m_orders = new ArrayList; ... > public string FirstName ... > private int areaCode; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: GridView and DDL
    ... private long m_LeaseID; ... private int m_RoomOrder; ... private string m_LeaseName; ... OracleConnection leaseConnection = new OracleConnection("user ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)