Constructor in Java In Java, constructor is a block of codes similar to method. It is called when an instance of object is created and memory is allocated for the object. It is a special type of method which is used to initialize the object. Note: It is called constructor because it constructs the values at the time of object creation. It is not necessary to write a constructor for a class. It is because java compiler creates a default constructor if your class doesn’t have any. Rules for creating java constructor There are basically two rules defined for the constructor. Constructor must have the same name as its class name Constructor must not have return type Types of java constructors two types of constructors in java: Default constructor (no-arg constructor) Parameterized constructor Java Default Constructor A constructor is called “Default Constructor” when it doesn’t have any parameter. Syntax of default constructor: ...
WHAT IS JAVA Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. Developer : Sun Microsystems (now owned by Oracle Corporation) Typing discipline : Static, strong, safe, nominative, manifest First appeared : May 23, 1995; 22 years ago Designed by : James Gosling License : GNU General Public License, Java Community Process Java is − Object Oriented − In Java, everything is an Object. Java can be easily extended since it is based on the Object model. Platform Independent − Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by the Virtual Machine (JVM) on whichever plat...