
Lectures / lecture3_2
.pdf
Multiple Constructors
public class Shirt {
... < declarations for field omitted > ...
//No-argument constructor public Shirt() {
//You could add some default processing here
}
//This constructor takes one argument
public Shirt(char colorCode ) { setColorCode(colorCode);
}
public Shirt(char colorCode, double price) {
this(colorCode);
setPrice(price); Chaining the constructors
}
If required, must be added explicitly
11 - 21 |
Copyright © 2011, Oracle and/or its affiliates. All rights reserved. |

Quiz
What is the default constructor for the following class? public class Penny {
String name = "lane";
}
a.public Penny(String name)
b.public Penny()
c.class()
d.String()
11 - 22 |
Copyright © 2011, Oracle and/or its affiliates. All rights reserved. |