0% found this document useful (0 votes)
106 views1 page

Java Constructors Guide

Constructors are invoked when new objects are created and have the same name as the class. They cannot have a return type or be overridden. Every class has at least one constructor provided either by the programmer or implicitly by the Java Virtual Machine as a no-argument constructor. Constructors call parent constructors through the super keyword and instance members cannot be accessed until after the parent constructor runs.

Uploaded by

aakritich
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views1 page

Java Constructors Guide

Constructors are invoked when new objects are created and have the same name as the class. They cannot have a return type or be overridden. Every class has at least one constructor provided either by the programmer or implicitly by the Java Virtual Machine as a no-argument constructor. Constructors call parent constructors through the super keyword and instance members cannot be accessed until after the parent constructor runs.

Uploaded by

aakritich
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Constructor Cheatsheet

 Constructor is invoked when a new object is created.


 Constructor’s can also be overloaded but it can not be overridden.
 Every class has at least one constructor. If user doesn’t provide any JVM will provide a default no arg constructor.
 Abstract class also has constructor.
 Constructor must have the same name as class.
 Constructor can’t have a return type.
 If a method with the same name as class has return type will be treated as normal member method and not
constructor.
 Constructor can have any access modifier(All).
 Default constructor is a no arg constructor which calls the no arg constructor of super class. In case super class
doesn’t have any no arg constructor then it will throw a run time exception.
 In case where a class has default constructor, its super class needs to have a no arg constructor.
 First statement of a constructor can be either this or super but can not be both at the same time.
 If coder doesn’t write any this or super call then compiler will add a call to super.
 Instance member can be accessible only after the super constructor runs.
 Interfaces do not have constructors.
 Constructor are not inherited. Hence can not be overridden.
 Constructor can not be directly invoked. It will be invoked(Implicitly) when a new object is created or a call by other
constructor.

You might also like