public class Triangle { public double base; // instance variable public double height; // instance variable public String color; // instance variable public static int numSides = 3; // static variable public Triangle(double base, double height, String color) { // base, height, and color are "local" to the Triangle constructor method // this.base, this.height, this.color belong to the Triangle instance this.base = base; this.height = height; this.color = color; } public double area() { return 0.5 * base * height; } // this is a static method! public static int sides() { // numSides is a static variable, meaning that it is // stored in the class (not in an instance!) return numSides; } public static void main(String[] args) { // we can call static methods and access static data without // having an instance of Triangle! System.out.println("Your triangle has " + Triangle.sides() + " sides."); // base, height, and color are local to main // yes, these are DIFFERENT variables than the ones with the same // name stored in the instance or local to the Triangle constructor double base = Double.valueOf(args[0]); double height = Double.valueOf(args[1]); String color = args[2]; // now we finally make an instance (object) of Triangle Triangle t = new Triangle(base, height, color); System.out.println("Your " + t.color + " triangle has area: " + t.area()); // And look, we can even access static data THROUGH a reference to // a specific object. Take a moment and ask yourself why this is always OK. System.out.println("Your triangle still has " + t.sides() + " sides."); } }