Questions and Answers
Questions and Answers
1. Demonstrate a Python program that defines a class "MyClass" with the attributes of name and
age , creates an instance of the class, and uses the instance to access the attribute.
2. Demonstrate a Python program that defines a class Car with a default constructor that
initializes attributes for brand and year, and a method display_info to print the car's details.
Create an object of the class and call the method to display the information.
3. Demonstrate a Python program that defines a class Animal with a constructor that takes name
and age as parameters, and a method display_info to print the name and age of the animal.
Create an object of the class and call the method to display the animal's details.
OR
4.
5.
6. Demonstrate a mini project BankAccount class(All attributes should be private) to simulate
basic banking operations such as depositing money, withdrawing money, checking account
balance, and displaying account details. Create an instance of the class with initial values and
demonstrate each of these operations.
7. Demonstrate a Python program using a class called Car that includes attributes for make,
model, mileage, and price. The program should include methods to display the car's details,
start and stop the car, and update its price. Provide an example of creating two car objects and
calling their methods.
8. Demonstrate a Python program using a class called Movie that includes attributes for Heroname
and year. creates an instance of the class, and uses the instance to access the attribute.
8. Write a Python program to create a class named Student with a protected attribute _name,
initialized to "Amir" in the constructor. Instantiate an object of the class and print the
protected attribute _name.
9. Write a Python program to create a class named Student with a protected attribute _name,
initialized to "Amir" in the constructor. Instantiate an object of the class and print the
protected attribute _name.
10. Create a Python program with a class Sms that has three attributes(a public, a protected and a
private): source1, source2, and source3, representing different social media sources. Initialize
these attributes through the constructor with values "Whatsapp", "Instagram", and
"Facebook". Instantiate an object of Sms and print the values of each attribute.
11. Create a Python program with a class Employee that includes a class attribute company set to
"Tech Corp". The class should have private attributes __emp_id and __name, as well as a
public attribute salary. Implement getter and setter methods for emp_id to control access to
this private attribute. Add a method display_employee to print employee details, including the
company name.
12. Demonstrate a Python program to define a class Parrot with attributes name and age, create
two objects of the class (parrot1 and parrot2), assign values to their attributes, And access the
attributes.
13. Implement a Python class Dog with name and breed as attributes. Create two objects (dog1
and dog2), assign specific values for their attributes, and display their details of the dog.
14. . Create a Python class named College with a constructor that initializes a public attribute
student name to "Amir". Define an object of the class, access its name attribute, and print the
value.
15. Write a Python program that demonstrates abstraction by creating an abstract class Vehicle
with an abstract method number_of_wheels(). Then, implement two concrete classes Car and
Bike that inherit from Vehicle and define the number of wheels for each. Instantiate the Car
and Bike classes and display the number of wheels for each vehicle.
16. Explain how to use super keyword and how method overriding in inheritance works by using
the class names as parent. Parent class person as attribute name and age Create child class
employee with attributes emp_id ,salary. And show the method overriding