Practice 50 Kotlin Inheritance Coding Questions, TechnoVlogs

Practice 50 Kotlin Inheritance Coding Questions


Q1. Write a Kotlin program to create a class Animal with a method sound(). Create a subclass Dog that overrides the sound() method.
  Expected Output: Woof!

Q2. Write a Kotlin program to create a class Person with properties name and age. Create a subclass Student that inherits from Person and adds a grade property.
  Input: name = "Alice", age = 20, grade = "A"
  Expected Output: Alice, 20, A

Q3. Write a Kotlin program to create a class Shape with a method area(). Create a subclass Rectangle that overrides the area() method.
  Input: length = 5, width = 4
  Expected Output: Area of Rectangle: 20

Q4. Write a Kotlin program to create a class Vehicle with a method move(). Create a subclass Car that overrides the move() method.
  Expected Output: Car is moving!

Q5. Write a Kotlin program to create a class Employee with properties name and salary. Create a subclass Manager that inherits from Employee and adds a department property.
  Input: name = "John", salary = 50000, department = "Sales"
  Expected Output: John, 50000, Sales

Q6. Write a Kotlin program to create a class Animal with a method eat(). Create a subclass Cat that overrides the eat() method.
  Expected Output: Cat is eating.

Q7. Write a Kotlin program to create a class Person with a method greet(). Create a subclass Teacher that inherits from Person and overrides the greet() method.
  Expected Output: Good morning, I am your teacher!

Q8. Write a Kotlin program to create a class Shape with properties length and width. Create a subclass Square that inherits from Shape and calculates the area.
  Input: length = 4, width = 4
  Expected Output: Area of Square: 16

Q9. Write a Kotlin program to create a class BankAccount with properties balance. Create a subclass SavingsAccount that inherits from BankAccount and adds an interest rate.
  Input: balance = 1000, interestRate = 5
  Expected Output: Balance after interest: 1050

Q10. Write a Kotlin program to create a class Animal with properties name and age. Create a subclass Dog that adds a method bark().
   Input: name = "Rex", age = 3
   Expected Output: Rex is barking!

Q11. Write a Kotlin program to create a class Shape with a method area(). Create a subclass Circle that overrides the area() method.
   Input: radius = 5
   Expected Output: Area of Circle: 78.54

Q12. Write a Kotlin program to create a class Book with properties title and author. Create a subclass EBook that inherits from Book and adds a fileSize property.
   Input: title = "Kotlin Basics", author = "Jane Doe", fileSize = 2
   Expected Output: EBook: Kotlin Basics by Jane Doe, File size: 2MB

Q13. Write a Kotlin program to create a class Person with properties name and age. Create a subclass Employee that adds a salary property.
   Input: name = "Alex", age = 28, salary = 40000
   Expected Output: Alex, 28, 40000

Q14. Write a Kotlin program to create a class Shape with properties length and width. Create a subclass Rectangle that calculates the area.
   Input: length = 6, width = 3
   Expected Output: Area of Rectangle: 18

Q15. Write a Kotlin program to create a class Person with a method introduce(). Create a subclass Student that overrides the introduce() method.
   Expected Output: Hi, I am a student!

Q16. Write a Kotlin program to create a class Employee with properties name and position. Create a subclass Manager that adds a method manage().
   Input: name = "Michael", position = "Manager"
   Expected Output: Michael is managing the team!

Q17. Write a Kotlin program to create a class Vehicle with properties make and model. Create a subclass Car that inherits from Vehicle and adds a method accelerate().
   Input: make = "Ford", model = "Focus"
   Expected Output: Ford Focus is accelerating!

Q18. Write a Kotlin program to create a class Person with properties name and age. Create a subclass Teacher that overrides the greet() method.
   Expected Output: Hello, I am your teacher!

Q19. Write a Kotlin program to create a class Shape with a method area(). Create a subclass Triangle that overrides the area() method.
   Input: base = 5, height = 6
   Expected Output: Area of Triangle: 15

Q20. Write a Kotlin program to create a class Person with properties name and age. Create a subclass Student that inherits from Person and adds a grade property.
   Input: name = "John", age = 20, grade = "B"
   Expected Output: John, 20, B

Q21. Write a Kotlin program to create a class Car with properties make and model. Create a subclass ElectricCar that adds a batteryCapacity property.
   Input: make = "Tesla", model = "Model S", batteryCapacity = 85
   Expected Output: Tesla Model S with 85 kWh battery

Q22. Write a Kotlin program to create a class Person with properties name and age. Create a subclass Employee that inherits from Person and adds a salary property.
   Input: name = "Sara", age = 30, salary = 50000
   Expected Output: Sara, 30, 50000

Q23. Write a Kotlin program to create a class Shape with properties length and width. Create a subclass Rectangle that calculates the perimeter.
   Input: length = 8, width = 3
   Expected Output: Perimeter of Rectangle: 22

Q24. Write a Kotlin program to create a class Animal with a method sound(). Create a subclass Cat that overrides the sound() method.
   Expected Output: Meow!

Q25. Write a Kotlin program to create a class Person with properties name and age. Create a subclass Employee that adds a method work().
   Input: name = "Emily", age = 35
   Expected Output: Emily is working!

Q26. Write a Kotlin program to create a class Person with properties name and age. Create a subclass Teacher that overrides the introduce() method.
   Expected Output: Hello, I am a teacher!

Q27. Write a Kotlin program to create a class Vehicle with properties make and model. Create a subclass Truck that adds a loadCapacity property.
   Input: make = "Ford", model = "F-150", loadCapacity = 2000
   Expected Output: Ford F-150 with 2000 kg load capacity

Q28. Write a Kotlin program to create a class Book with properties title and author. Create a subclass EBook that adds a fileSize property.
   Input: title = "Kotlin for Beginners", author = "Sam", fileSize = 3
   Expected Output: EBook: Kotlin for Beginners by Sam, File size: 3MB

Q29. Write a Kotlin program to create a class Shape with a method area(). Create a subclass Circle that calculates the area.
   Input: radius = 7
   Expected Output: Area of Circle: 153.94

Q30. Write a Kotlin program to create a class Employee with properties name and salary. Create a subclass Manager that adds a department property.
   Input: name = "Ryan", salary = 70000, department = "HR"
   Expected Output: Ryan, 70000, HR

Q31. Write a Kotlin program to create a class Employee with properties name and age. Create a subclass Intern that adds a duration property.
   Input: name = "Olivia", age = 22, duration = "6 months"
   Expected Output: Olivia, 22, 6 months

Q32. Write a Kotlin program to create a class Vehicle with properties make and model. Create a subclass ElectricCar that adds a chargingTime property.
   Input: make = "Nissan", model = "Leaf", chargingTime = 30
   Expected Output: Nissan Leaf, Charging Time: 30 minutes

Q33. Write a Kotlin program to create a class Shape with properties length and width. Create a subclass Square that overrides the area() method.
   Input: length = 5
   Expected Output: Area of Square: 25

Q34. Write a Kotlin program to create a class Person with properties name and age. Create a subclass Teacher that overrides the greet() method.
   Expected Output: Hello, I am your teacher!

Q35. Write a Kotlin program to create a class Animal with a method sleep(). Create a subclass Dog that overrides the sleep() method.
   Expected Output: Dog is sleeping.

Q36. Write a Kotlin program to create a class Vehicle with properties make and model. Create a subclass Motorcycle that adds a helmetRequired property.
   Input: make = "Harley", model = "Davidson", helmetRequired = true
   Expected Output: Harley Davidson, Helmet required: true

Q37. Write a Kotlin program to create a class Student with properties name and marks. Create a subclass GraduateStudent that adds a degree property.
   Input: name = "Tom", marks = 85, degree = "Masters"
   Expected Output: Tom, 85, Masters

Q38. Write a Kotlin program to create a class Vehicle with properties make and model. Create a subclass Bicycle that adds a gearCount property.
   Input: make = "Giant", model = "Escape", gearCount = 21
   Expected Output: Giant Escape with 21 gears

Q39. Write a Kotlin program to create a class Employee with properties name and position. Create a subclass Intern that adds a school property.
   Input: name = "Sophie", position = "Intern", school = "University of XYZ"
   Expected Output: Sophie, Intern at University of XYZ

Q40. Write a Kotlin program to create a class Animal with properties name and sound. Create a subclass Cat that overrides the sound() method.
   Expected Output: Meow!

Q41. Write a Kotlin program to create a class Person with properties name and age. Create a subclass Employee that adds a method work().
   Expected Output: Employee is working!

Q42. Write a Kotlin program to create a class Car with properties make and model. Create a subclass ElectricCar that adds a method charge().
   Expected Output: Electric car is charging!

Q43. Write a Kotlin program to create a class Animal with properties name and sound. Create a subclass Cow that overrides the sound() method.
   Expected Output: Moo!

Q44. Write a Kotlin program to create a class Employee with properties name and salary. Create a subclass Manager that adds a method manage().
   Input: name = "Sarah", salary = 75000
   Expected Output: Sarah is managing the team!

Q45. Write a Kotlin program to create a class Person with properties name and age. Create a subclass Student that adds a method study().
   Expected Output: Student is studying!

Q46. Write a Kotlin program to create a class Shape with properties length and width. Create a subclass Circle that adds a method circumference().
   Input: radius = 5
   Expected Output: Circumference: 31.42

Q47. Write a Kotlin program to create a class Employee with properties name and salary. Create a subclass SalesEmployee that adds a method sell().
   Expected Output: Sales employee is selling products!

Q48. Write a Kotlin program to create a class Shape with properties length and width. Create a subclass Square that overrides the area() method.
   Input: length = 4
   Expected Output: Area of Square: 16

Q49. Write a Kotlin program to create a class Student with properties name and marks. Create a subclass GraduateStudent that adds a degree property.
   Input: name = "Rachel", marks = 90, degree = "PhD"
   Expected Output: Rachel, 90, PhD

Q50. Write a Kotlin program to create a class Person with properties name and age. Create a subclass Employee that adds a method promote().
   Input: name = "James", age = 40
   Expected Output: James has been promoted!

Share on Social Media