Access to class attributs by coding in its mother class method definition

Hi all,
How can I retrieve information about a class attributs by coding?
And is it possible to access to the attributs of the Child class from the Mother class?
REPORT  ztest_method.
******      CLASS mother DEFINITION
CLASS mother DEFINITION.
  PUBLIC SECTION.
    METHODS: get_data.
ENDCLASS.                    "mother DEFINITION
******      CLASS child DEFINITION
CLASS child DEFINITION inheriting from mother.
ENDCLASS.                    "child DEFINITION
*******      CLASS mother IMPLEMENTATION
CLASS mother IMPLEMENTATION.
  METHOD get_data.
***Can I access to child class attributs here?
  ENDMETHOD.                    "get_data
ENDCLASS.                    "mother IMPLEMENTATION
DATA oref TYPE REF TO CHILD.
DATA: method TYPE string.
DATA: cla_name(20).
START-OF-SELECTION.
  CREATE OBJECT oref .
  CALL METHOD oref->method).  "Here I want to access to this class's attribut without redefine it

Hi,
a very easy way is to define an attribute TYPE REF TO DATA in the super class and write generic access methods which work with it by dereferencing it and assigning a field symbol. This might even save you the effort of creating a class hierarchy, because one class may be able to handle all the data objects whose types are only known at run-time.
In the below example, the only specific thing about the sub class is the constructor in which the data object is created and typed:
REPORT  ztesta.
*       CLASS lcl_mother DEFINITION
CLASS lcl_mother DEFINITION.
  PUBLIC SECTION.
    METHODS get_data EXPORTING es_data TYPE any.
    METHODS set_data IMPORTING is_data TYPE any.
  PROTECTED SECTION.
    DATA mr_data TYPE REF TO data.
ENDCLASS.                    "lcl_mother DEFINITION
*       CLASS lcl_child1 DEFINITION
CLASS lcl_child1 DEFINITION INHERITING FROM lcl_mother.
  PUBLIC SECTION.
    METHODS constructor.
ENDCLASS.                    "lcl_child1 DEFINITION
DATA:
  lr_child      TYPE REF TO lcl_mother,
  ls_but000_in  TYPE        but000,
  ls_but000_out type        but000.
START-OF-SELECTION.
  CREATE OBJECT lr_child TYPE lcl_child1.
  ls_but000_in-partner = '0000004711'.
  lr_child->set_data( ls_but000_in ).
  lr_child->get_data( IMPORTING es_data = ls_but000_out ).
  write: / ls_but000_out-partner.
*       CLASS lcl_mother IMPLEMENTATION
CLASS lcl_mother IMPLEMENTATION.
  METHOD get_data.
    FIELD-SYMBOLS:
      <fs_data> TYPE ANY.
    ASSIGN mr_data->* TO <fs_data>.
    MOVE-CORRESPONDING <fs_data> TO es_data.
  ENDMETHOD.                    "get_data
  METHOD set_data.
    FIELD-SYMBOLS:
      <fs_data> TYPE ANY.
    ASSIGN mr_data->* TO <fs_data>.
    MOVE-CORRESPONDING is_data TO <fs_data>.
  ENDMETHOD.                    "set_data
ENDCLASS.                    "lcl_mother IMPLEMENTATION
*       CLASS lcl_child1 IMPLEMENTATION
CLASS lcl_child1 IMPLEMENTATION.
  METHOD constructor.
    super->constructor( ).
    CREATE DATA mr_data TYPE but000.
  ENDMETHOD.                    "constructor
ENDCLASS.                    "lcl_child1 IMPLEMENTATION
Another variant would be to define an attribute MV_DATA which is typed individually in each sub class and program dynamically against it in the super class using field symbols.
*& Report  ZTESTA
REPORT  ztesta.
*       CLASS lcl_mother DEFINITION
CLASS lcl_mother DEFINITION.
  PUBLIC SECTION.
    METHODS get_data EXPORTING es_data TYPE any.
    METHODS set_data IMPORTING is_data TYPE any.
ENDCLASS.                    "lcl_mother DEFINITION
*       CLASS lcl_child1 DEFINITION
CLASS lcl_child1 DEFINITION INHERITING FROM lcl_mother.
  PUBLIC SECTION.
    DATA: ms_data TYPE but000.
    METHODS constructor.
ENDCLASS.                    "lcl_child1 DEFINITION
*       CLASS lcl_child2 DEFINITION
CLASS lcl_child2 DEFINITION INHERITING FROM lcl_mother.
  PUBLIC SECTION.
    DATA: ms_data TYPE t000.
    METHODS constructor.
ENDCLASS.                    "lcl_child1 DEFINITION
DATA:
  lr_child1     TYPE REF TO lcl_mother,
  lr_child2     TYPE REF TO lcl_mother,
  ls_but000     TYPE        but000,
  ls_t000       TYPE        t000.
START-OF-SELECTION.
  CREATE OBJECT lr_child1 TYPE lcl_child1.
  lr_child1->get_data( IMPORTING es_data = ls_but000 ).
  WRITE: / ls_but000-partner.
  CREATE OBJECT lr_child2 TYPE lcl_child2.
  lr_child2->get_data( IMPORTING es_data = ls_t000 ).
  WRITE: / ls_t000-mwaer.
*       CLASS lcl_mother IMPLEMENTATION
CLASS lcl_mother IMPLEMENTATION.
  METHOD get_data.
    FIELD-SYMBOLS:
      <fs_data> TYPE ANY.
    ASSIGN ('MS_DATA') TO <fs_data>.
    es_data = <fs_data>.
  ENDMETHOD.                    "get_data
  METHOD set_data.
    FIELD-SYMBOLS:
      <fs_data> TYPE ANY.
    ASSIGN ('MS_DATA') TO <fs_data>.
    <fs_data> = is_data.
  ENDMETHOD.                    "set_data
ENDCLASS.                    "lcl_mother IMPLEMENTATION
*       CLASS lcl_child1 IMPLEMENTATION
CLASS lcl_child1 IMPLEMENTATION.
  METHOD constructor.
    super->constructor( ).
    SELECT SINGLE * FROM but000 INTO ms_data.
  ENDMETHOD.                    "constructor
ENDCLASS.                    "lcl_child1 IMPLEMENTATION
*       CLASS lcl_child2 IMPLEMENTATION
CLASS lcl_child2 IMPLEMENTATION.
  METHOD constructor.
    super->constructor( ).
    SELECT SINGLE * FROM t000 INTO ms_data.
  ENDMETHOD.                    "constructor
ENDCLASS.                    "lcl_child2 IMPLEMENTATION
I hope this helps!
Regards,
Thorsten

Similar Messages

  • Please Help!!! Problems access other classes methods

    I am having a problem accessing another classes methods varibles. I have tried a number of ways but with no success. Here is my problem:
    I have the main(), from there it's calls the class GetVar(), GetVar stores info in Class HousingForVar(), and finially, I have a class TryinToTalkToHousing() that I use to access HousingForVar()'s methods. I know I can use the keyword new but if I do that then it erases over the data I put in. Please can anyone help, this has been driving me nutz all day. Thank you in advance.
    Roman03
    ***EACH CLASS IS A DIFFERENT FILE****
    public class TestMain
         public static void main( String args[] )
              GetVar getVarible = new GetVar();
              getVarible.heroF();
    import java.util.Scanner;
    public class GetVar
         public void heroF()
              String someEntered;
              Scanner input = new Scanner( System.in);
              System.out.println("Enter a string: ");
              someEntered = input.next();
              HousingForVar houseForData = new HousingForVar(someEntered);
              System.out.printf("Retieved from Class GetVar, you entered: %s\n", houseForData.getCollectVar() );
    import java.util.Scanner;
    public class HousingForVar
         private String getData;
         public HousingForVar(String enterInfo)
              getData = enterInfo;
         public void setGetVar(String enterInfo)
              getData = enterInfo;
         public String getCollectVar()
              return getData;
    import java.util.Scanner;
    public class TryinToTalkToHousing
         public void someMeth()
              String getInfoFromHousing;          
              System.out.printf("Started out at TryinToTalkToHousing Class\n Retieved from Class GetVar from %s\n",
              houseForData.getCollectVar() );
    \* I know this doesn't work, but if I make a new object of the class HousingForVar it's going to write over my input, so what do I do? I am still learning, Please help*\

    I don't use 1.5, so you'll have to convert it back, but see if you can follow the flow of this
    import java.io.*;
    class TestMain
      GetVar getVarible;
      public TestMain()
        getVarible = new GetVar();
        getVarible.heroF();
        System.out.println("******");
        new TryinToTalkToHousing(this).someMeth();
      public static void main(String[] args){new TestMain();}
    class GetVar
      HousingForVar houseForData;
      public void heroF()
        try
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          System.out.print("Enter a string: ");
          String someEntered = br.readLine();
          houseForData = new HousingForVar(someEntered);
          System.out.println("Retieved from Class GetVar, you entered: "+houseForData.getCollectVar()+"\n");
        catch(Exception e){e.printStackTrace();}
    class HousingForVar
      private String getData;
      public HousingForVar(String enterInfo)
        getData = enterInfo;
      public void setGetVar(String enterInfo)
        getData = enterInfo;
      public String getCollectVar()
        return getData;
    class TryinToTalkToHousing
      TestMain parent;
      public TryinToTalkToHousing(TestMain t){parent = t;}
      public void someMeth()
        System.out.println("Started out at TryinToTalkToHousing Class\n"+
        "Retieved from Class GetVar, you entered: "+parent.getVarible.houseForData.getCollectVar()+"\n");
    }

  • Accessing private class methods

    This program works, but I am having some problem grasping the concept. If class Room can access methods in class House using gethWidth() and getHeight(), why is it that class Type cannot access those same
    methods. Instead, it can only access setWidth() and
    setHeight()?
    class House {
    private double width;//width of room
    private double length;//length of the room
    double getWidth() {return width;}
    double getLength() {return length;}
    void setWidth(double w) {width=w;}
    void setLength(double l) {length=l;}
    void showdim() {
    System.out.println("My townhouse has two bedrooms.");
    class Room extends House {
    String bedroom;
    double area() {
    return getWidth() * getLength();
    void showBedroom() {
    System.out.println("The biggest room is the" + " " + bedroom + ".");
    class Type {
    public static void main(String args[]) {
    Room r1=new Room();
    Room r2=new Room();
    r1.setWidth(14.5);
    r1.setLength(20.6);
    r1.bedroom="master bedroom";
    r2.setWidth(15.2);
    r2.setLength(15.3);
    r2.bedroom="Guest Room";
    System.out.println();
    r1.showdim();
    r1.showBedroom();
    System.out.println();
    System.out.println("The area of the" + " " + r1.bedroom+ " " +
    "equals"+ " "+ r1.area()+ " " + "square feet.");
    }

    Thanks to all. But the comments provided so far does not answer my question. Over the past few days I have struggled over the question and I think I found the answer. Others are welcome to comment.
    Initially, "width" and "length" were decleared as private in class "House". For other classes to gain access, they had to use "accessor methods". Two accessor methods were decleared: "getWidth" and "getHeight"; and "setWidth" and "setLength". The first two methods "return"; the last two were "void". In class Room, I set up a method to return the calculation, so I used "getWidth and "getLength". In class "Type" I had to use the other method "setWidth", since I was declearing the actual values. Makes sense?

  • Accessing Super Class methods

    Hi,
    If I have a Subclass that overrides a method in a superclass, is it possible to call that method from the superclass?
    Thanks

    Hi thanks for the reply, but that works for static methods, I'm trying to figure out non-static methods. Below, I want to call the method a() from the superclass using an instance of the subclass.
    class superclassA
    void a()
    System.out.println("in method a");
    class subclassA extends superclassA
    void a()
    System.out.println("in method b");
    public class overtest
    public static void main(String [] args)
    subclassA sub = new subclassA();
    superclassA.a();//non-static method a cannot be referenced from a static context
    Thanks!

  • Error accessing constnt public attribute of a class in an overwrite method.

    Hi Gurus,
    I am facing an error while accessing a constant public attribute while using it in the overwrite-exit of a methods.
    The constant which is declared as public in the attribute section of the class is not available in the overwrite-exit of the method.
    Please suggest me how to access the public attributes in the overwtire exits of the methods.
    Thanks.

    Hi Ramneek,
    Let me explain you the entire scenario:
    Actually we are trying to ehance the SAP standard class : CL_FITV_POWL_FEEDER_TRIPS in ECC 6.0 EHP 5 .
    We tried to create and overwrite-exit of the method "IF_POWL_FEEDER~GET_ACTIONS".
    Overwrite-exit of a method is just like a method which will be called instead of the standard method : IF_POWL_FEEDER~GET_ACTIONS.
    But the problem which we are facing here is that the Attributes which are defined in the class CL_FITV_POWL_FEEDER_TRIPS,  are getting accessed from the overwrite-exit method.
    Becuase of this we are not able to implement our custom logic.

  • Access to class-attribute by Interface-reference

    Hi OO-Gurus,
    I use an implementation of BADI ME_PROCESS_REQ_CUST to fill and handle user-defined fields in the MM-Purchase-Requisition, method IF_EX_ME_PROCESS_REQ_CUST~OPEN.
    There I  use a reference variable which refers to an interface (type ref to IF_PURCHASE_REQUISITION_ITEM) to access the item-object. My problem is that I need to have access to the class-attribute my_state. The corresponding class lcl_req_item is defined locally (LMEREQF01). So I can’t use  a reference variable with reference to this class (so widening cast using the interface-reference is not possible) .. Does anyone know a trick how to access the class-attribute anyway?
    Coding:
      data:  l_item_list       TYPE MMPUR_REQUISITION_ITEMS,
               l_item             TYPE MMPUR_REQUISITION_ITEM,
               l_item_akt       TYPE mereq_item,
               l_item_ref        TYPE ref to IF_PURCHASE_REQUISITION_ITEM. 
      l_item_list = im_header->get_items().
      loop at l_item_list into l_item.
        l_item_akt = l_item-item->get_data( ).
        l_item_ref = l_item-item.
      endloop.
    (Debugging the code, I manage by doubleclicking the fieldcontent of l_item_ref (e.g ) to show the content of the class-attribute my_state. This works only if the field “Interface” in the Debugger is empty because then I see the attributes of the class. If the field Interface is filled with “IF_PURCHASE_REQUISITION_ITEM”, there aren’t any attributes shown.)
    Thanks in advance for your kind help!!
    Nicole

    Hello Nicole
    The following sample coding shows you how to solve your problem. Please do not ask me how I came across this solution.
    However, if you are studying it carefully you may stumble across a most beautiful property of field-symbols as I did.
    METHOD if_ex_me_process_req_cust~open.
      DATA: l_item_list TYPE mmpur_requisition_items,
      l_item TYPE mmpur_requisition_item,
      l_item_akt TYPE mereq_item,
      l_item_ref TYPE REF TO if_purchase_requisition_item.
      DATA:
        ld_attr         TYPE string,
        lo_obj          TYPE REF TO object.
      FIELD-SYMBOLS:
        <lo_lcl>        TYPE ANY,
        <ls_item>       TYPE mereq_item,
        <ls_itemx>      TYPE mereq_itemx.
      l_item_list = im_header->get_items( ).
      LOOP AT l_item_list INTO l_item.
        l_item_akt = l_item-item->get_data( ).
        l_item_ref = l_item-item.
        lo_obj     ?= l_item-item.  " casting to root object !!!!!
        ld_attr = 'MY_STATE'.
        ASSIGN lo_obj->(ld_attr) TO <lo_lcl>.
        ld_attr = 'MY_STATE->ITEM'.
        ASSIGN lo_obj->(ld_attr) TO <ls_item>.
    "    ASSIGN l_item_ref->(ld_attr) TO <ls_item>.  " does not work...
        ld_attr = 'MY_STATE->ITEMX'.
        ASSIGN lo_obj->(ld_attr) TO <ls_itemx>.
      ENDLOOP.
      " NOTE: data definition of local class lcl_req_item_state (fg MEREQ)
    **    DATA:  item           TYPE mereq_item,
    **           itemx          TYPE mereq_itemx,
    **           header         TYPE REF TO lcl_req_header,
    **           ref_item       TYPE REF TO lcl_req_item,
    **           acct_container TYPE REF TO lcl_acct_container,
    **           source         TYPE REF TO cl_source_of_supply_mm,
    **           release_state  TYPE REF TO cl_release_state_mm,
    **           text_manager   TYPE REF TO lcl_text_manager,
    **           bom            TYPE REF TO lcl_bom,
    **           funds_mgt_active TYPE mmpur_bool VALUE mmpur_no,
    **           aktyp          TYPE aktyp,
    **           no_auth        TYPE mmpur_bool VALUE mmpur_no,
    **           release_op     type mmpur_bool value mmpur_no,
    **           persistent     TYPE mmpur_bool VALUE mmpur_no,
    **           checked        TYPE mmpur_bool VALUE mmpur_no,
    **           manual_configuration TYPE mmpur_bool,
    **           input_buffer_changed TYPE mmpur_bool VALUE mmpur_no,
    **           changed        TYPE mmpur_bool,
    **           broken_rules   TYPE lty_mask,
    **           referenced_rules TYPE lty_mask,
    **           chp_changes    TYPE mmchp_chp_list,
    **           dcm_manager    TYPE REF TO if_revision_manager_dcm,
    **           "DCM Retrofit
    **           rel_state_after_release TYPE REF TO cl_release_state_mm,
    **           "DCM Retrofit
    **           chdoc_container TYPE REF TO lcl_chdoc_container,
    **           "DCM Retrofit
    **           service_changed TYPE mmpur_bool,
    **           "DCM Retrofit
    **           determinants   TYPE lty_item_determinants.
    ENDMETHOD.
    Regards
      Uwe

  • Accessing impl class attribute

    Hi Experts,
    if i declare one variable in controller class of a view and how can access the variable in contex naode .

    Hi srinivas.yangal,
    You can access the View implementation Class Attributes in Context.
    1] Go to Context Node Implementation Class
    2] Create a attribute GV_VIEW_CONTROLLER in Impl class of Context Node.
    DATA : GV_VIEW_CONTROLLER TYPE REF TO CL_BSP_WD_VIEW_CONTROLLER .
    3] Go to INIT method of Context Node.
    4] Assign instance LV_VIEW_CONTROLLER to GV_VIEW_CONTROLLER of Context Node Impl. Class.
    GV_VIEW_CONTROLLER = LV_VIEW_CONTROLLER.
    Then you can access your Instance attributes defined in View Impl. class inside the context node through GV_VIEW_CONTROLLER attribute as follows.
    ABC = GV_VIEW_CONTROLLER->XYZ.
    Reward points if useful.
    Kind Regards,
    Dhananjay.
    Edited by: Dhananjay SAP CRM on Nov 24, 2011 12:56 PM

  • Is it possible to access a consant attribute with a JSF expression?

    I have a class with constant attributes like this:
    public static final int CONSTANT_VALUE = 111;
    How do I access them with a JSF expression?
    #{myBean.CONSTANT_VALUE} does not work.
    Do I have to write getters for them? I heared somewhere that its not bossible
    to access them directly.
    Thanks!

    just write a get method of this attribute

  • Accessing Java Classes from Forms

    Is is possible to access a Java class from Forms? I have been
    creating an Active X control that returns a Java object, and from
    that I can call methods on that object, but I would really like
    to do that without having and Active X control in the mix. Any
    suggestions?
    null

    Oracle Developer Team wrote:
    : Robert Nocera (guest) wrote:
    : : Oracle Developer Team wrote:
    : : : hey robert -
    : : : Developer 6.0 provides this ability for web deployment.
    You
    : : can
    : : : insert your own custom Java components into your
    application
    : : and
    : : : they will appear in the application when it is run via the
    : web.
    : : : If you look at the documentation for 6.0, there are a few
    : : : section son Pluggable Java Components and JavaBeans that
    : : : describes what is provided and how you use the interfaces
    : and
    : : : classes we provide.
    : : : A whitepaper on this topic will be posted to the OTN
    : shortly,
    : : as
    : : : well as some samples that illustrate how to go about doing
    : it.
    : : : cheers!
    : : : -Oracle Developer Team-
    : : Thanks for the quick response. Is there any way to access
    : those
    : : classes without being in a web deployment. That's probably
    : not
    : : totally out of the question, but what we had in mind was
    : adding
    : : some Java Functionality (actually connectictivity to some
    EJBs
    : : that we have) to existing forms. Currently there forms are
    : not
    : : deployed in a "web" environment and are just run from the
    : forms
    : : runtime engine.
    : : -Rob
    : hey again robert -
    : there's no easy way (yet!) to call out from forms runtime
    : process to a Java application.
    : We've played around some with creating an ORA_FFI interface to
    : JNI and then wrappering this with PL/SQL code. We've been able
    : to make calling into an EJB running in 8i from a forms runtime
    : work using this approach.
    : Let me know if this is of interest to you and I can post the
    : stuff we've currently got. It's no more than a simple demo and
    : is not complete. It requires quite a bit of manual coding on
    : the PL/SQL side since the interface emulates JNI (FindClass,
    : GetMethodID, CallMethodID, etc.).
    : cheers!
    : -the Oracle Developer Team-
    I'd be interested in this ORA_FFI doc you've been playing with.
    Would you please email it to me or post it.
    null

  • In onLoad JavaScript, I'm getting "Error: Permission denied to access property 'classes'" when I access Components.classes; how do I enable that permission?

    I need to emulate several ActiveX functions in my client's web application. I have located several Mozilla web pages that describe how to do the things I need, and I have attempted to implement those instructions. However, I can't seem to get past the first line of code. In my web page, I am calling a JavaScript function using the onLoad attribute of the <body> tag. I am using the Navigator object to determine that the browser is Firefox. I then attempt to access the extension classes using the following code on lines 51 and 52 of the Download.js file:
    var C = Components;
    var CC = C.classes;
    The Web Console gives me these two messages:
    [13:51:55.621] The Components object is deprecated. It will soon be removed. @ http://distribution:781/NewDDI/DownLoad.js:51
    [13:51:55.621] Error: Permission denied to access property 'classes' @ http://distribution:781/NewDDI/DownLoad.js:52
    How do I enable adequate permission to be able to access the Components classes?

    I think Components is available only in extensions (or otherwise privileged code) and not in ordinary web pages.

  • Access parent class?

    I'm just wondering if there's some way to access the class that instantiates a class from the instantiated class. Say if I had a class that has a Vector and creates a bunch of other classes that are added to the Vector. Is it possible for the instances of the class to access the Vector? I realize that this is poor OO, but I was just wondering if Java has some way of making this work, or if this just has "rethink idea" all over it... Thanks for your time.

    You can pass a reference variable pointing at the parent to the child object and store it there. Via this pointer you can reach the parent. It's common practice. This for example will print "parent". The parent just let go of the child but the child holds a reference to its parent,
    class Child {
       Parent parent;
       public Child (Parent p) {
          parent = p;
          parent.print();
    class Parent {
       public Parent () {
           new Child(this);
       public void print() {
          System.out.println("Parent");
    Parent p = new Parent();

  • Controlling Access to Classes

    Hi,
    I know that you can use the keywords private and protected for methods and variables, but can you also use these keywords at the class level? I understand that the public modifier enables a class to be accessed outside of its package, and that if no modifier is used, then the class can be accessed by any class within the same package. But what would the private and protected keywords mean at the class level?
    Thx.

    I know that you can use the keywords private and
    protected for methods and variables, but can you also
    use these keywords at the class level? I understand
    that the public modifier enables a class to be
    accessed outside of its package, and that if no
    modifier is used, then the class can be accessed by
    any class within the same package. But what would the
    private and protected keywords mean at the class
    level?They cause a compile-time error.
    It's can be explained.
    private modifer forbid(? a don't know how to translate :) ) access to class, why you must need class that you can't access?
    protected modifer used when you inheritr something/ but tou newer inherite class. You inherit it'as member.
    It was simple question :)

  • Access global data of report in global class methods?

    Hi all,
    I have defined one global class in SE24 and i am using methods of this class in report program.
    Can i access global data of my report program in class methods directly without declaring it as IMPORT
    parameter?
    Thanks,
    Apita

    Hi,
    Well, now you did confuse me: first you asked about using global data of a report program in global class (created in SE24), and the answer is: no, you can't directly access the global data of another program in a method of global class (yes, you should pass them via importing parameters), and you shouldn't even consider using indirect means of doing so via special form of ASSIGN statement reserved for internal use by SAP. The ASSIGN will not work if someone reuses the global class elsewhere in the system without loading your report. Don't ever program such atrocious dependencies in global class...
    And now you ask about the use "in method implementation in report program"..? Just to be sure - you can't program the implementation of a global class method in a report program.
    You can program a local class inheriting from a global class and redefine/re-implement methods of such global super-class in a report program. Global data of report program, including the selection screen, would be directly accessible to such local class. It would still not be a good idea to use this access:
    Conversely, within an encapsulated unit, that is, within a class, you should avoid accessing more global data directly. Within methods, you should generally modify attributes of the class only. Write access to global data outside the class is not recommended. Accessing data in this way should only be done using specially marked methods, if at all. The use of methods of a class should not evoke any side effects outside the class itself.
    cheers
    Jānis
    Message was edited by: Jānis B

  • Accessing a Class in a Package[in a dir]  via Different Directory

    Hi,
    I am trying to access a class belonging to a package in a directory via another class in a different directory.
    However, there are problems.
    Here is what I do:
    I created a source file ProtectedTest2.java
    package com.java.MyLesson.ch8;
    public class ProtectedTest2
    private int iN1, iN2;
    public ProtectedTest2(){ }
    public ProtectedTest2(int iA, int iB)
    iN1 = iA;
    iN2 = iB;
    public String getNumbers()
    return "Numbers are: "+iN1 +" and "+ iN2;
    } After that, I compiled this file with javac -d C:\\MyUserClasses ProtectedTest2.java. There was no problem.
    I then, created another source file TestPro2.java and imported ProtectedTest2 in TestPro
    import javax.swing.JOptionPane;
    import com.java.MyLesson.ch8.ProtectedTest2;
    public class TestPro2 extends ProtectedTest2
    public TestPro2()
    ProtectedTest2 pro = new ProtectedTest2(8,12);
    JOptionPane.showMessageDialog(null, p.getNumbers() );
    public static void main(String args[])
    new TestPro2();
    System.exit(0);
    } Then, I continue to compile TestPro2.java like this:
    javac -classpath C:\\MyUserClasses TestPro2.java -- there was no problem, but when I try to execute
    TestPro2, the error I got was :
    Exception in thread "main" java.lang.NoClassDefFoundError: com/java/MyLesson/ch8/ProtectedTest2
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader . java:502)
    I understand that the class loader will look into the classpath[current directory] if it cannot find the user- defined class [ProtectedTest2.class] in the standard and optional java packages. Why did the application raise error if I have specified the classpath for the ProtectedTest2.class [which is in C:\MyUserClasses] during the compilation of TestPro2.java ?
    Can someone please correct me and tell me what is the mistake here ?
    Thank you all! :-)

    You need to have C:\MyUserClasses in the class search path both when compiling and running.
    Where the compiler finds a depency class is not saved in the generated .class file, so the runtime is on its own when it needs to find it. If C:\MyUserClasses is not in the class search path, the runtime doesn't know that it should be looking for ProtectedTest2 there. In addition to MyUserClasses you want to search for classes in the current directory (the path ".") so the command to execute TestPro2 is:
    java -classpath .;C:\MyUserClasses TestPro2
    See also the document on how classes are found (if you already haven't)
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/findingclasses.html

  • I need Internet Explorer 5.5 to access my classes

    Hi
    I try accessing my classes, but when I do I get a message that says "In order to provide you with the most efficient access to our site, we ask you that you use Internet Explorer 5.5 or higher to view the site. Please click on the Get Microsoft Internet Explorer logo below to download the latest version"
    I tried accessing my site with Safari and Firefox and get the same message, Please help.

    You can set the User Agent in Safari (use newest supported Safari, for security) and
    if you have OnyX by Titanium Software, you can use its configuration options to have
    the Safari's User Agent stay put. Otherwise, it will revert once shut down to a standard
    view and the Developer menu bar may disappear from the Safari browser.
    {Or I should say, this worked in mine; perhaps in an earlier Safari and it was carried forward.}
    Once you enable the Developer menu (and User Agent) with OnyX utility, a free tool
    from Titanium Software, the menu and ability to have Safari seen by web sites as a
    different browser stays enabled. {And OnyX is good for much more: maintenance.}
    When you have OnyX in the system, launch it, enter password then note this path:
    OnyX> Parameters> Safari> Enable debug menu>
    For some reason, this keeps my Safari's (including latest version) developer menu
    and User Agent from going away; it is always present. If this does not work for you
    then there may be some other thing going on in my computer. There was a tweak
    a few years ago, a freeware, that also enabled the User Agent; doubt I installed it.
    • Or you could get Camino browser and see if its user agent lets you use stubborn
    web sites engineered by fools with stone axes and wooden clubs, in IE clothing.
    Even Opera may allow you an option to fool those sites made by M$ followers.
    Good luck & happy computing!
    { edited }

Maybe you are looking for