/** * Simple example of inner classes * @author gtowell * Created: Mar 2021 */ public class OutCl { /** * The inner class */ private class InnCl { private int value1; // a value private String value2; // another value public InnCl(int v1, String v2) { this.value1 = v1; this.value2 = v2; } public String toString() { return value1 + " " + value2; } } /** * Use the inner class */ public void worker() { InnCl icl1 = new InnCl(1, "Bob"); InnCl icl2 = new InnCl(2, "Carol"); icl1.value1 = 3; icl2.value2 = "Alice"; System.out.println(icl1 + "\n" + icl2); } public static void main(String[] args) { OutCl ocl = new OutCl(); ocl.worker(); } }