Properties and Action:
Object:
// Object is the combination of properties and actions
// Properties is noun and Actions are Verb
// CLASS: Class Defines the blueprint for set of object of the same type
// OBJECT: Each object is unique real and has properties and action
// obj1 and obj2 which is the object reference hold different space in the memory.
// object is made by calling the constructor
public class ObjectDemo {
public static void main(String[] args) {
CircleClass obj1 = new CircleClass();
obj1.findArea(2.22);
CircleClass obj2 = new CircleClass();
obj2.findArea(5.55);
}
}
class CircleClass{
double radius;
double area;
public void findArea(double radius) {
this.radius = radius;
area = 3.14 * this.radius * this.radius ;
System.out.println("The area is: "+area);
}
}



No comments:
Post a Comment