Constructors
Whenever an instance is created in the method, it is called the constructor of that particular class and is executed by default.
If the user has not written/provided any constructor, the compiler will automatically insert the empty constructor.
A method name similar to its respective class name and method does not return any value.
Overloading is possible but not overriding.
An example of a Java program with a constructor chain
The following is an example of a constructor chain in a Java program:
package MyFirstPackage; class SampleClass4 { SampleClass4(){ System.out.println("executing sample meathod"); } } class SampleClass3 extends SampleClass4 { SampleClass3(){ System.out.println("executing sample method 2"); } } public class Constructors ...
Get Learning Selenium Testing Tools - Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.