Constructors in Java
Rules for creating Java constructor
Note: We can use access modifiers while declaring a constructor. It controls the object creation. In other words, we can have private, protected, public or default constructor in Java.
Types of Java constructors
Java Default Constructor
Syntax of default constructor:
Example of default constructor
In this example, we are creating the no-arg constructor in the Bike class. It will be invoked at the time of object creation. |
0 comments:
Post a Comment