Skip to content

Instantly share code, notes, and snippets.

@shibli049
Created September 25, 2025 06:47
Show Gist options
  • Select an option

  • Save shibli049/4c07a7a31f2f7174d42d1243eca55a0b to your computer and use it in GitHub Desktop.

Select an option

Save shibli049/4c07a7a31f2f7174d42d1243eca55a0b to your computer and use it in GitHub Desktop.
class Y {
int value;
Y(int value) {
this.value = value;
display();
}
public void display() {
IO.println("Value: " + value);
}
}
class X extends Y {
int start, end;
String greet = "Hello!";
X(int start, int end) {
// Prologue
if (start > end) {
throw new IllegalArgumentException("start > end");
}
IO.println(this); // Error - You can't observe current instance in prologue
this.start = start; // OK - assignment to an uninitialized field
this.end = end; // OK
greet = "Hi!"; //Error - assignment to an initialized field
this.toString(); // Error - refers to instance method
super(end - start); // Or, this(<with optional args>)
// Epilogue
// OK - Call a method of the current instance in epilogue
this.display();
}
@Override
public void display() {
IO.println("Start: " + start + ", End: " + end + ", Greet: " + greet);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment