<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/**
 * This program demonstrates the use of this() in a constructor to call a
 * different constructor of the same class with a different signature.
 */

public class ConstructorThis {
   public static void main(String[] args) {
      System.out.println(new Foo("ham").lunch);
      System.out.println(new Foo().lunch);
   }
}

class Foo {
   String lunch;

   Foo() {
      this("turkey");
   }

   Foo(String s) {
      lunch = s + " sandwich";
   }
}</pre></body></html>