Java Object and Classes
This lesson mainly focused on Java object and class, and describes the features of Java object-oriented programming.
Java has following OOPS features:
In this lesson our major focus on Objects and Classes.
What is Object?
In real-world an entity that has state and its behavior is known as an object.
For Example:
In real world object and software object have conceptually similar characteristics. In terms of object-oriented programming, software objects also have a state and behavior.
What is a class?
Primary purpose of a class is to held data/information. This is achieved with attributes which is also known as data members.
The member functions determine the behavior of the class i.e. provide definition for supporting various operations on data held in form of an object.
Defining a Class in Java
Syntax:
public class class_name
{
Data Members;
Methods;
}
Example:
public class Car
{
public:
double color; // Color of a car
double model; // Model of a car
}
Class Members
Data and functions are members.
Data Members and methods must be declared within the class definition.
Example:
public class Cube
{
int length; // length is a data member of class Cube
int breadth; // breadth is a data member of class Cube
int length ; // Error redefinition of length
}
0 comments:
Post a Comment