public class Basics { // in file named "Basics.java"
private int n;
public Basics() { // default constructor
this.n = 1;
}
public Basics(int n) { // another constructor
this.n = n; // set a private variable
}
public void hello() { // a public method with no return
for(int i = 0; i < n; i++) {
System.out.println("Hello!");
}
}
public static void main(String[] args) { // will be run from command line
Basics b1 = new Basics(5); // says hello 5 times
Basics b2 = new Basics(); // say hello default num of times
System.out.println("* b1");
b1.hello();
System.out.println("* b2");
b2.hello();
}
}