Class Declaration--> Syntax of class declaration is as follows:
(class modifiers) class (class name)
(extends clause) (implements clause) // Class header
{ // Class body
-- field declarations
--method declarations
--nested class declarations
--nested interface declarations
--constructor declarations
--initializer blocks
--constructor declarations
--initializer blocks
}
Methods of a Class--> They are the class members and are also called operations. They define behaviour of the class.
Methods of a Class--> They are the class members and are also called operations. They define behaviour of the class.
Syntax of their declaration is as follows:
(method modifiers) (return type) (method name) ((formal parameter list))
(throws clause) // Method prototype
(throws clause) // Method prototype
{ // Method body
--local variable declarations
--nested local class 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.
--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.
It has following syntax:
(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.
Its syntax is:
classname(){super();}
No comments:
Post a Comment