Java Classes and Objects
Java is a true object-oriented language and therefore the underlying structure of all java programs is classes. Anything we wise to represent in a java program must be encapsulated in a class that defines the state and behaviour of the basic program components known as objects.
An object is anything that really exists in the world and can be distingushed from others. Every thing that we see physically will come into this definition, for example:- human being, a book, tree, a table, a pen, and so on.
Collection of objects is called class. It is a logical entity.
Syntax for class:-
[Access Specifier/Modifier-List] class < class name> [extends SuperClass] [implements Interface-List]
Or
< class modifiers> class < class name>< formal type parameter list> < extends clause>< implements clause> // Class header
{ // class body
< field declarations>
< method declarations>
< nested class declarations>
< nested interface declarations>
< nested enum declarations>
< constructor declarations>
< initializer blocks>
}// End of class body
Syntax for object:-
classname reference_variable = new classname([parameter-list]);
Ex:-
An object is anything that really exists in the world and can be distingushed from others. Every thing that we see physically will come into this definition, for example:- human being, a book, tree, a table, a pen, and so on.
Collection of objects is called class. It is a logical entity.
Syntax for class:-
[Access Specifier/Modifier-List] class < class name> [extends SuperClass] [implements Interface-List]
Or
< class modifiers> class < class name>< formal type parameter list> < extends clause>< implements clause> // Class header
{ // class body
< field declarations>
< method declarations>
< nested class declarations>
< nested interface declarations>
< nested enum declarations>
< constructor declarations>
< initializer blocks>
}// End of class body
Syntax for object:-
classname reference_variable = new classname([parameter-list]);
Ex:-
//start of class PersonClass Person{//Start of Main Methodpublic static void main(String args[]){Person p = new Person();} //End of Main Method} //End of Person Class
No comments:
Post a Comment