Attribute

From Abap2Java

Jump to: navigation, search

Contents

ABAP

To do...

Java

member attribute

A member attribute encapsulates data by containing primitive datatypes or other classes. A modifier controlls the accessibility.

public class MyClass {
   // private attributes
   private int position;
   private Vector v;
   // public access through member methods : Getter and Setter
   public int getPosition() { 
      return this.position; 
   }
   public void setPosition(int position) { 
      this.position = position; 
   }
}

static attribute

If the association of an attribute to every instance is not wanted, the modifier static allows the definition of an attribute which will be accessible through the class context.

public class Circle() {
   public static double pi = 3.14;
   public getCircumference() {
      return 2 * pi * this.radius;
   }
}
System.out.print(Circle.pi);

final attribute

The value of a final attribute can not be changed from the program. Final fields are often written in capital letters.

public class Circle() {
   public static final double PI = 3.14;
}

See also
class, method, modifier

Personal tools