27 Lecture

CS201

Midterm & Final Term Short Notes

Classes And Objects

Classes and objects are key concepts in object-oriented programming. A class is a blueprint or template for creating objects, while an object is an instance of a class. A class defines the attributes and methods that an object will have, while a


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is a class in object-oriented programming? a) An instance of an object b) A blueprint or template for creating objects c) A method for manipulating data d) A data structure for storing information

Answer: b

  1. What is an object in object-oriented programming? a) A blueprint or template for creating classes b) A method for manipulating data c) An instance of a class d) A data structure for storing information

Answer: c

  1. What is encapsulation in object-oriented programming? a) The ability of objects of different classes to be treated as if they were of the same class b) The ability to hide the internal workings of an object from the outside world c) The ability to create a new class from an existing class d) The ability to initialize the attributes of an object

Answer: b

  1. What is inheritance in object-oriented programming? a) The ability of objects of different classes to be treated as if they were of the same class b) The ability to hide the internal workings of an object from the outside world c) The ability to create a new class from an existing class d) The ability to initialize the attributes of an object

Answer: c

  1. What is polymorphism in object-oriented programming? a) The ability of objects of different classes to be treated as if they were of the same class b) The ability to hide the internal workings of an object from the outside world c) The ability to create a new class from an existing class d) The ability to initialize the attributes of an object

Answer: a

  1. What is a constructor in object-oriented programming? a) A method for manipulating data b) An instance of a class c) A data structure for storing information d) A method used to initialize objects

Answer: d

  1. What is the difference between a class and an object? a) A class is a blueprint or template, while an object is an instance of that class b) A class is an instance of an object, while an object is a blueprint or template c) A class and an object are the same thing d) A class is a method, while an object is a data structure

Answer: a

  1. What is an attribute in object-oriented programming? a) A method for manipulating data b) An instance of a class c) A data variable that describes the state of an object d) A data structure for storing information

Answer: c

  1. What is a method in object-oriented programming? a) A data variable that describes the state of an object b) An instance of a class c) A function that defines the behavior of an object d) A data structure for storing information

Answer: c

  1. What is the advantage of using classes and objects in object-oriented programming? a) Encapsulation of data and functionality b) Inheritance and polymorphism for code reuse c) A more flexible and dynamic code structure d) All of the above

Answer: d



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is the difference between a class and an object in object-oriented programming? Answer: A class is a blueprint or template that defines the attributes and behaviors of objects, while an object is an instance of a class.

  2. What is the purpose of encapsulation in object-oriented programming? Answer: The purpose of encapsulation is to hide the internal details of an object from the outside world and provide a well-defined interface for interacting with the object.

  3. What is inheritance in object-oriented programming? Answer: Inheritance is the ability of a new class to be created from an existing class, inheriting its attributes and methods.

  4. What is polymorphism in object-oriented programming? Answer: Polymorphism is the ability of objects of different classes to be treated as if they were of the same class, allowing for more flexible and dynamic code.

  5. What is a constructor in object-oriented programming? Answer: A constructor is a special method that is used to initialize objects when they are created.

  6. What is the difference between a public and private attribute in a class? Answer: A public attribute can be accessed and modified by any code that interacts with the object, while a private attribute can only be accessed and modified by methods within the class.

  7. What is a method in object-oriented programming? Answer: A method is a function that is associated with a class or object and defines its behavior.

  8. What is the purpose of the "self" keyword in Python classes? Answer: The "self" keyword is used to refer to the object that the method is being called on, allowing the method to access and modify the object's attributes.

  9. How does inheritance promote code reuse in object-oriented programming? Answer: Inheritance allows new classes to be created that inherit the attributes and methods of an existing class, reducing the need to write redundant code.

  10. What are some advantages of using classes and objects in programming? Answer: Advantages of using classes and objects include encapsulation of data and functionality, code reuse through inheritance and polymorphism, and the ability to create more modular and flexible code.

In object-oriented programming, a class is a blueprint or template that defines the attributes and behaviors of objects. Objects, on the other hand, are instances of classes that contain data and functionality. Classes allow developers to create reusable code by encapsulating data and functionality within a single entity. Encapsulation is a key principle of object-oriented programming that allows the internal details of an object to be hidden from the outside world. This is achieved by defining the attributes and methods of a class with public, private, and protected access modifiers. Public attributes and methods can be accessed and modified by any code that interacts with the object, while private attributes and methods can only be accessed and modified by methods within the class. Inheritance is another important feature of object-oriented programming that allows new classes to be created from existing classes. Inheritance promotes code reuse by allowing developers to create subclasses that inherit the attributes and methods of a superclass. This helps to reduce redundant code and increase the modularity of a program. Polymorphism is a concept in object-oriented programming that allows objects of different classes to be treated as if they were of the same class. This allows for more dynamic and flexible code, as different objects can be passed to a method and still behave in the same way. Constructors are special methods that are used to initialize objects when they are created. In Python, constructors are defined using the init() method. Overall, classes and objects are a powerful tool in modern programming, offering increased modularity, encapsulation, and code reuse. By understanding the principles and features of object-oriented programming, developers can create more flexible and dynamic programs that are easier to maintain and update over time.