javacodex.com
Java Examples
Java Examples
memu home questions

Basis Java Class

This is a simple example of a java class with setters and getters.

Source: (JavaClass.java)

public class JavaClass {
  String name;
 
  public void setName(String n){
    name = n;
  }
 
  public String getName(){
    return name;
  }
 
  public static void main(String args[]){
    JavaClass jc = new JavaClass();
    jc.setName("John");
    System.out.println("Hello " + jc.getName());      
  }
}
 

Output:

# java JavaClass
Hello John

Contact: javacodex@yahoo.com