Page 47 - CA_Blue( J )_Class9
P. 47

{
                    Circle cr= new Circle ();           // an object named cr of class Circle has been created
                    cr.area();                          // Calling area() method of cr object
                    cr.diameter();                      // Calling diameter() method of cr object
                    }
                 Here, "cr" is the object created with the help of "new" operator. It is the object of the "Circle" class.  Also "area()",
                 "diameter()" functions of the object "cr" are called.

                 3.3.2 Message Passing between Objects
                 In Java, objects interact with each other by invoking methods on one another. This interaction, where one object
                 sends a message to another object by calling its methods, is known as Message Passing. The concept is analogous
                 to real-world objects communicating with each other, where one object requests the behaviour of another.

                 Message Passing occurs when an object calls the method of another object, which can lead to the exchange
                 of data or triggering specific behaviours. This mechanism is fundamental in Object-Oriented Programming, as it
                 allows objects to collaborate and perform complex tasks.

                 The dot operator (.) is used to invoke methods and pass messages between objects. The syntax is:

                 objectName.methodName();
                 For example:

                 class Car {
                     void start() {
                         System.out.println("Car started.");
                     }

                     void stop() {
                         System.out.println("Car stopped.");
                     }
                 }
                 class Driver {
                     public static void main(String[] args) {
                         Car myCar = new Car();
                         myCar.start(); // Sending a "start" message to the car object
                         myCar.stop(); // Sending a "stop" message to the car object
                     }
                 }
                 In this example, the Driver object sends "start" and "stop" messages to the Car object. The Car object receives
                 these messages and executes the corresponding methods.


                     3.4 PROPERTIES OF CLASS AND OBJECT
                 Let us learn the properties of the class and object.

                 3.4.1 Class is an Object Factory
                 In the real world, a factory is a place where many similar products are manufactured from a common prototype.
                 For example, in a car manufacturing plant, many cars of the same model are produced using the same design and
                 machinery.


                                                                          Elementary Concept of Objects and Classes  45
   42   43   44   45   46   47   48   49   50   51   52