Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ThisUsage {
- int id;
- ThisUsage(int i) {
- this.id = i;// access and initialize field from the constructor
- }
- ThisUsage() {
- this(1);// invoke the constructor with one parameter.
- }
- public static void main(String[] args) {
- ThisUsage tu = new ThisUsage();
- ThisUsage tu2 = new ThisUsage(2);
- System.out.println("If no id provided, the default id is-->" + tu.id);
- System.out.println("otherwise, print the user-defined id -->" + tu2.id);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement