MyTetra Share
Делитесь знаниями!
Constructors
Время создания: 04.09.2017 21:32
Текстовые метки: knowledge
Раздел: Java - Tutorial - Object and Classes
Запись: xintrea/mytetra_db_mcold/master/base/1504549943fa0e9azt22/text.html на raw.githubusercontent.com

When discussing about classes, one of the most important sub topic would be constructors. Every class has a constructor. If we do not explicitly write a constructor for a class, the Java compiler builds a default constructor for that class.

Each time a new object is created, at least one constructor will be invoked. The main rule of constructors is that they should have the same name as the class. A class can have more than one constructor.

Following is an example of a constructor −

Example

public class Puppy {
   public Puppy() {
   }

   public Puppy(String name) {
      // This constructor has one parameter, name.
   }
}

Java also supports Singleton Classes where you would be able to create only one instance of a class.

Note − We have two different types of constructors. We are going to discuss constructors in detail in the subsequent chapters.

Так же в этом разделе:
 
MyTetra Share v.0.59
Яндекс индекс цитирования