Skip to main content

Posts

Showing posts with the label class 12th Chapter-8 Classes and object in Java.

ads1

class 12th Chapter-8 Classes and object in Java.

    A class contains both data (referred to as attributes), and program cod e Creating objects Creating an object from a class requires the following steps : Declaration : A variable (reference variable) name of type class is declared with syntax <class name> <variable name> • Instantiation : Keyword new is used to create the object by allocating memory • Initialization: Constructor (a special type of method) is called to initialize the newly created Using new keyword, we can create an object. Operator new allocates the memory for an object and returns the address When an object is created, in addition to allocating memory, a special method called 'constructor is executed to perform initial task. rl = new Room(); Here, parentheses are important; In object-oriented programming (OOP) languages, creating an object is also called object instantiation. An instance for an object is created by allocating memory to store the data for that object. Instance variables define the a

ads2