// sample of 2 classes , one is an
application with a main method
// and the other is a simple class
with 1 instance variable and 3 methods
// keep for future reference
package untitled14;
public class student
{
protected int age; //also can make
"private"
public student()
{
age=0;
}
public void setAge(int c)
{
age=c;
}
public int getAge()
{
return age;
}
}
package untitled14;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Application1
{
public static void main(String args[])
{
//how to create an object...
student shepherd = new student(); //call to
the constructor, creates the object
shepherd.setAge(30);
int p = shepherd.getAge();
JOptionPane.showMessageDialog(null,"Age
is "+p);
//another option: "JOptionPane.showMessageDialog(null,"Age
is "+shepherd.getAge());"
System.exit(0);
}
}