Created
September 25, 2025 06:47
-
-
Save shibli049/4c07a7a31f2f7174d42d1243eca55a0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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