Practice 50 Kotlin Object-Oriented Programming Questions, TechnoVlogs

Practice 50 Kotlin Object-Oriented Programming Questions


Q1. Write a Kotlin program to create a class Person with properties name and age. Create an object of the class and print the details.
  Input: name = "John", age = 30
  Expected Output: John, 30

Q2. Write a Kotlin program to create a class Car with properties make, model, and year. Create an object and print the details.
  Input: make = "Toyota", model = "Camry", year = 2020
  Expected Output: Toyota Camry 2020

Q3. Write a Kotlin program to create a class Student with properties name, age, and marks. Create an object and calculate the average marks.
  Input: marks = [80, 85, 90]
  Expected Output: Average Marks: 85

Q4. Write a Kotlin program to create a class Book with properties title and author. Create an object and display the book details.
  Input: title = "Kotlin Programming", author = "Jane Doe"
  Expected Output: Kotlin Programming by Jane Doe

Q5. Write a Kotlin program to create a class Rectangle with properties length and width. Create an object and calculate the area.
  Input: length = 5, width = 3
  Expected Output: 15

Q6. Write a Kotlin program to create a class Person with a function greet() to print a greeting message.
  Input: name = "Alice"
  Expected Output: Hello, Alice!

Q7. Write a Kotlin program to create a class Employee with properties name and salary. Create an object and display the salary.
  Input: name = "James", salary = 50000
  Expected Output: James earns 50000

Q8. Write a Kotlin program to create a class BankAccount with properties accountNumber and balance. Create an object and perform a deposit operation.
  Input: accountNumber = "123456", balance = 2000, depositAmount = 1000
  Expected Output: Balance after deposit: 3000

Q9. Write a Kotlin program to create a class Car with a method startEngine() that prints "Engine started".
  Expected Output: Engine started

Q10. Write a Kotlin program to create a class Shape with properties length and width. Create an object and calculate the perimeter.
   Input: length = 6, width = 4
   Expected Output: Perimeter: 20

Q11. Write a Kotlin program to create a class Person with a constructor that accepts name and age. Print the details.
   Input: name = "John", age = 25
   Expected Output: John is 25 years old

Q12. Write a Kotlin program to create a class Student with properties name and marks. Create a method to check if the student passed (marks >= 50).
   Input: name = "Alice", marks = 55
   Expected Output: Alice passed

Q13. Write a Kotlin program to create a class Movie with properties title and rating. Create an object and display the movie details.
   Input: title = "Inception", rating = 8.8
   Expected Output: Inception has a rating of 8.8

Q14. Write a Kotlin program to create a class Dog with properties breed and color. Create an object and print the dog's details.
   Input: breed = "Labrador", color = "Yellow"
   Expected Output: Labrador Yellow

Q15. Write a Kotlin program to create a class BankAccount with a function withdraw() that deducts an amount from the balance.
   Input: balance = 5000, withdrawalAmount = 1000
   Expected Output: Balance after withdrawal: 4000

Q16. Write a Kotlin program to create a class Circle with a property radius. Create an object and calculate the circumference.
   Input: radius = 7
   Expected Output: Circumference: 43.9823

Q17. Write a Kotlin program to create a class Employee with properties id, name, and salary. Create an object and display the employee details.
   Input: id = 101, name = "Sam", salary = 60000
   Expected Output: Sam, 101, 60000

Q18. Write a Kotlin program to create a class Account with properties accountNumber and balance. Create an object and perform a transfer operation.
   Input: balance = 10000, transferAmount = 2000
   Expected Output: Balance after transfer: 8000

Q19. Write a Kotlin program to create a class Rectangle with properties length and width. Create an object and calculate the diagonal.
   Input: length = 3, width = 4
   Expected Output: Diagonal: 5.0

Q20. Write a Kotlin program to create a class Product with properties name and price. Create an object and apply a discount.
   Input: name = "Laptop", price = 1000, discount = 10
   Expected Output: Price after discount: 900

Q21. Write a Kotlin program to create a class Person with properties name and age. Create a function to check if the person is an adult.
   Input: name = "Emma", age = 20
   Expected Output: Emma is an adult

Q22. Write a Kotlin program to create a class Rectangle with properties length and width. Create an object and calculate the area and perimeter.
   Input: length = 6, width = 2
   Expected Output: Area: 12, Perimeter: 16

Q23. Write a Kotlin program to create a class Student with properties name and age. Create a function to print the student's details.
   Input: name = "David", age = 21
   Expected Output: David is 21 years old

Q24. Write a Kotlin program to create a class Vehicle with properties make, model, and year. Create an object and display the details.
   Input: make = "Ford", model = "Fusion", year = 2018
   Expected Output: Ford Fusion 2018

Q25. Write a Kotlin program to create a class Person with a property name. Create a function introduce() to print "Hello, my name is <name>".
   Input: name = "Tom"
   Expected Output: Hello, my name is Tom

Q26. Write a Kotlin program to create a class Employee with properties name, salary, and position. Create an object and display the employee details.
   Input: name = "Jane", salary = 70000, position = "Manager"
   Expected Output: Jane, Manager, 70000

Q27. Write a Kotlin program to create a class Dog with properties name and age. Create an object and check if the dog is a puppy (age < 1).
   Input: name = "Rex", age = 0.5
   Expected Output: Rex is a puppy

Q28. Write a Kotlin program to create a class Rectangle with properties length and width. Create a method to check if the rectangle is a square.
   Input: length = 5, width = 5
   Expected Output: It is a square.

Q29. Write a Kotlin program to create a class Student with properties id and marks. Create a method to calculate the total marks.
   Input: marks = [80, 85, 90]
   Expected Output: Total Marks: 255

Q30. Write a Kotlin program to create a class Account with properties balance. Create a method to apply an interest rate.
   Input: balance = 2000, interestRate = 5
   Expected Output: Balance after interest: 2100

Q31. Write a Kotlin program to create a class Movie with properties title and duration. Create a method to calculate the remaining time if the movie has started.
   Input: duration = 120, elapsedTime = 40
   Expected Output: Remaining time: 80 minutes

Q32. Write a Kotlin program to create a class Person with properties firstName and lastName. Create a method to display the full name.
   Input: firstName = "Alice", lastName = "Johnson"
   Expected Output: Alice Johnson

Q33. Write a Kotlin program to create a class Car with properties make, model, and year. Create a method to check if the car is old (if year is less than 2000).
   Input: make = "Honda", model = "Civic", year = 1999
   Expected Output: This is an old car.

Q34. Write a Kotlin program to create a class Book with properties title and author. Create a method to display a quote from the book.
   Input: title = "Kotlin for Beginners", author = "John Smith"
   Expected Output: Quote from Kotlin for Beginners: "Learn Kotlin the easy way!"

Q35. Write a Kotlin program to create a class Person with properties name, age, and gender. Create a method to check if the person is male or female.
   Input: name = "Emily", gender = "Female"
   Expected Output: Emily is Female

Q36. Write a Kotlin program to create a class Employee with properties id, name, and salary. Create a method to increase the salary.
   Input: id = 102, name = "David", salary = 50000, increase = 10
   Expected Output: Salary after increase: 55000

Q37. Write a Kotlin program to create a class Course with properties name and duration. Create a method to display the course details.
   Input: name = "Kotlin Programming", duration = 10
   Expected Output: Kotlin Programming for 10 hours

Q38. Write a Kotlin program to create a class Point with properties x and y. Create a method to calculate the distance from the origin (0, 0).
   Input: x = 3, y = 4
   Expected Output: Distance from origin: 5.0

Q39. Write a Kotlin program to create a class Person with properties age. Create a method to check if the person is eligible to drive (age >= 18).
   Input: age = 20
   Expected Output: Eligible to drive

Q40. Write a Kotlin program to create a class Product with properties name and price. Create a method to apply a discount.
   Input: name = "TV", price = 500, discount = 15
   Expected Output: Price after discount: 425

Q41. Write a Kotlin program to create a class Circle with a property radius. Create a method to calculate the area of the circle.
   Input: radius = 6
   Expected Output: Area: 113.097

Q42. Write a Kotlin program to create a class Employee with properties id and salary. Create a method to calculate the annual salary.
   Input: salary = 50000
   Expected Output: Annual Salary: 600000

Q43. Write a Kotlin program to create a class Shape with properties length and width. Create a method to check if the shape is a square.
   Input: length = 8, width = 8
   Expected Output: It is a square.

Q44. Write a Kotlin program to create a class Animal with properties name and species. Create a method to display the animal's details.
   Input: name = "Tiger", species = "Big Cat"
   Expected Output: Tiger is a Big Cat

Q45. Write a Kotlin program to create a class Employee with properties name and id. Create a method to display employee details.
   Input: name = "Ethan", id = "E124"
   Expected Output: Ethan E124

Q46. Write a Kotlin program to create a class Product with properties name and price. Create a method to apply a sales tax.
   Input: price = 100, salesTax = 8
   Expected Output: Price after tax: 108

Q47. Write a Kotlin program to create a class Customer with properties name and balance. Create a method to deduct from the balance.
   Input: balance = 2000, amount = 500
   Expected Output: Balance after deduction: 1500

Q48. Write a Kotlin program to create a class Teacher with properties name and subject. Create a method to display teacher details.
   Input: name = "Mr. Smith", subject = "Math"
   Expected Output: Mr. Smith teaches Math

Q49. Write a Kotlin program to create a class Vehicle with properties make and model. Create a method to start the vehicle.
   Expected Output: Vehicle started

Q50. Write a Kotlin program to create a class Person with properties name and age. Create a method to display the age of the person.
   Input: name = "Sophia", age = 22
   Expected Output: Sophia is 22 years old

Share on Social Media