Last active
August 31, 2021 12:10
-
-
Save minte9/4be7eaf71f4d7889d52203b195c563a7 to your computer and use it in GitHub Desktop.
Java / OOP/ Constructor - https://www.minte9.com/java/oop-introduction-constructor-1187
This file contains 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
/** | |
* Write constructor and method for Output class. | |
* The output() prints the <name> instance variable | |
*/ | |
class App { | |
public static void main(String[] args) { | |
Output o = new Output("John"); | |
o.output(); // John | |
} | |
} | |
/** | |
* SOLUTION | |
*/ | |
class Output{ | |
private String name; | |
public Output(String name) { | |
this.name = name; | |
} | |
public void output() { | |
System.out.println(name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment