(class modifiers) class (class name)
(extends clause) (implements clause) // Class header
{ // Class body
-- field declarations
--constructor declarations
--initializer blocks
Methods of a Class--> They are the class members and are also called operations. They define behaviour of the class.
(throws clause) // Method prototype
{ // Method body
--local variable declarations
--statements
}
Method Overloading--> This means several methods share same name but have different argument list.
Constructor--> It is a special method which is used to initialize state of an object when it is created using new operator.
(accessibility modifier) (class name) ((formal parameter list))
(throws clause) // Constructor header
{ // Constructor body
--local variable declarations
--nested local class declarations
--statements
}
However there are few constraints for a method to be constructor:
a) Their modifiers can be only accessibility modifiers.
b) They cannot have a return type
c) Their should be same as the class name.
Default Constructor--> It is the constructor with no argument. Its syntax is: classname()
Implicit Default Constructor-->If no constructor is defined in the class, then implicit default constructor is provided by java.
classname(){super();}