课程: Java Essential Training: Syntax and Structure

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Constructors

Constructors

- [Instructor] In addition to using setter methods to assign values to fields of a class, you can also use a constructor. Constructor are used to initialize an object or set up its state in some way. All objects have a constructor. And the very first type of constructor is the default constructor. This is a default constructor. The default constructor is known as such because it does not have a parameter list. This means, if someone wanted to create a rectangle object, and they did not want to set the length or the width just yet, then they could use this constructor without passing in any values. The default constructor is typically used to assign default values to fields. In Java, a default constructor is always defined implicitly. So even if you don't declare it explicitly, as we have done here, it still exists by default under the covers. Essentially, it's a blank constructor that does nothing. Let's dissect this…

内容