public class GetnSet {
String name = "Sponge Bob";
public static void main( String[ ] args ) {
// Creates a Person object.
Person myObj = new Person( );
// Sets the value of the name variable.
myObj.setName( args[0] );
// Gets the value of the name variable.
System.out.println( myObj.getName( ) );
}
}
class Person {
// private = restricted access
private String name = "Digi Mon";
// Getter
public String getName( ) { return name; }
// Setter
public void setName( String newName ) { name = newName; }
}
|