Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Lectures / lecture3_2

.pdf
Скачиваний:
33
Добавлен:
14.10.2016
Размер:
396.85 Кб
Скачать

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.

Соседние файлы в папке Lectures