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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.