Practice 50 Kotlin Class Coding Questions, TechnoVlogs

Practice 50 Kotlin Class Coding Questions


Q1. Write a Kotlin program to create a class named Person with a property name and a function to print the name.
  Input: name = "John"
  Expected Output: John

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

Q3. Write a Kotlin program to create a Rectangle class with length and width as properties. Create a function to calculate the area of the rectangle.
  Input: length = 5, width = 3
  Expected Output: 15

Q4. Write a Kotlin program to create a class Book with properties title and author. Print 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 Student with properties name and age. Create a function to print the student details.
  Input: name = "Alice", age = 20
  Expected Output: Alice is 20 years old

Q6. Write a Kotlin program to create a Circle class with a property radius. Create a function to calculate the area of the circle.
  Input: radius = 7
  Expected Output: 153.93804

Q7. Write a Kotlin program to create a Person class with a property name and a constructor to initialize the name.
  Input: name = "Robert"
  Expected Output: Robert

Q8. Write a Kotlin program to create a Car class with properties make, model, and year. Create a function to display the car's year.
  Input: make = "Honda", model = "Civic", year = 2019
  Expected Output: 2019

Q9. Write a Kotlin program to create a class Employee with properties id, name, and salary. Create a method to give a salary increase of 10%.
  Input: id = 101, name = "Sam", salary = 50000
  Expected Output: Salary after increase: 55000

Q10. Write a Kotlin program to create a class Person with a function greet that takes a name and prints a greeting message.
   Input: name = "Tom"
   Expected Output: Hello, Tom!

Q11. Write a Kotlin program to create a class BankAccount with properties accountNumber and balance. Create a method to deposit money into the account.
   Input: accountNumber = "123456", balance = 5000, depositAmount = 2000
   Expected Output: Balance after deposit: 7000

Q12. Write a Kotlin program to create a class Dog with a property breed and a function bark that prints "Woof".
   Input: breed = "Labrador"
   Expected Output: Woof

Q13. Write a Kotlin program to create a class Car with properties make, model, and year. Create a method to display the car's details.
   Input: make = "Ford", model = "Fiesta", year = 2018
   Expected Output: Ford Fiesta 2018

Q14. Write a Kotlin program to create a class Person with properties name and age. Create a function to check if the person is eligible to vote.
   Input: name = "Emma", age = 19
   Expected Output: Emma is eligible to vote.

Q15. Write a Kotlin program to create a class Movie with properties title and rating. Create a method to display the movie's rating.
   Input: title = "Inception", rating = 8.8
   Expected Output: Inception has a rating of 8.8

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

Q17. Write a Kotlin program to create a class Product with properties name, price, and quantity. Create a method to calculate the total price.
   Input: name = "Laptop", price = 1000, quantity = 2
   Expected Output: Total Price: 2000

Q18. Write a Kotlin program to create a class Vehicle with a property speed. Create a method to increase the speed.
   Input: speed = 50, increase = 20
   Expected Output: Speed after increase: 70

Q19. Write a Kotlin program to create a class Employee with properties name and salary. Create a method to display the salary.
   Input: name = "John", salary = 60000
   Expected Output: Salary: 60000

Q20. Write a Kotlin program to create a Person class with a property age. Create a method to check if the person is an adult.
   Input: age = 18
   Expected Output: Person is an adult

Q21. Write a Kotlin program to create a class Point with properties x and y. Create a method to display the point's coordinates.
   Input: x = 5, y = 7
   Expected Output: Point coordinates: (5, 7)

Q22. Write a Kotlin program to create a class BankAccount with properties balance. Create a method to withdraw money from the account.
   Input: balance = 1000, withdrawalAmount = 500
   Expected Output: Balance after withdrawal: 500

Q23. Write a Kotlin program to create a class Circle with property radius. Create a method to calculate the circumference.
   Input: radius = 4
   Expected Output: 25.13274

Q24. Write a Kotlin program to create a class Person with properties name, age, and address. Print the person's full details.
   Input: name = "Jake", age = 30, address = "123 Street"
   Expected Output: Jake, 30, 123 Street

Q25. Write a Kotlin program to create a class Account with a property balance. Create a method to transfer money from one account to another.
   Input: balance = 5000, transferAmount = 2000
   Expected Output: Balance after transfer: 3000

Q26. Write a Kotlin program to create a class Shape with properties length and width. Create a method to calculate the perimeter of the rectangle.
   Input: length = 5, width = 3
   Expected Output: 16

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

Q28. Write a Kotlin program to create a class Student with properties name, age, and grade. Create a method to check if the student passed.
   Input: grade = 70
   Expected Output: Student passed

Q29. Write a Kotlin program to create a class Employee with properties name, id, and salary. Create a method to display the details of the employee.
   Input: name = "Emma", id = "E123", salary = 50000
   Expected Output: Emma, E123, 50000

Q30. Write a Kotlin program to create a class Phone with properties brand and price. Create a method to apply a discount.
   Input: brand = "Samsung", price = 1000, discount = 10
   Expected Output: Price after discount: 900

Q31. Write a Kotlin program to create a class Animal with a property name. Create a method to display the animal's name.
   Input: name = "Lion"
   Expected Output: Lion

Q32. Write a Kotlin program to create a class Car with properties model, color, and year. Create a method to display car details.
   Input: model = "Tesla", color = "Red", year = 2022
   Expected Output: Tesla Red 2022

Q33. Write a Kotlin program to create a class Library with properties bookTitle and author. Create a method to display book details.
   Input: bookTitle = "Kotlin for Beginners", author = "John Smith"
   Expected Output: Kotlin for Beginners by John Smith

Q34. Write a Kotlin program to create a class Student with properties id, name, and marks. Create a method to print the student's details.
   Input: id = 101, name = "James", marks = 85
   Expected Output: 101 James 85

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

Q36. Write a Kotlin program to create a class Employee with properties id and salary. Create a method to calculate the bonus.
   Input: id = 102, salary = 50000
   Expected Output: Bonus: 5000

Q37. Write a Kotlin program to create a class Car with properties make, model, and year. Create a method to check if the car is new (if year is greater than 2020).
   Input: make = "BMW", model = "X5", year = 2021
   Expected Output: This is a new car.

Q38. Write a Kotlin program to create a class Person with properties name, age, and gender. Create a method to display personal details.
   Input: name = "Alice", age = 28, gender = "Female"
   Expected Output: Alice, 28, Female

Q39. 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 = 10
   Expected Output: 314.159

Q40. Write a Kotlin program to create a class Product with properties name and price. Create a method to increase the price.
   Input: name = "Shampoo", price = 5, increase = 1
   Expected Output: Price after increase: 6

Q41. Write a Kotlin program to create a class Account with a property balance. Create a method to withdraw money from the account.
   Input: balance = 1000, withdrawAmount = 300
   Expected Output: Balance after withdrawal: 700

Q42. Write a Kotlin program to create a class Rectangle with properties length and width. Create a method to calculate the perimeter.
   Input: length = 8, width = 4
   Expected Output: 24

Q43. Write a Kotlin program to create a class Car with properties make, model, and year. Create a method to display the car's age.
   Input: make = "Ford", model = "Mustang", year = 2010
   Expected Output: Car age: 15

Q44. 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 = "David", marks = 55
   Expected Output: David passed

Q45. Write a Kotlin program to create a class Circle with a property radius. Create a method to calculate the diameter.
   Input: radius = 6
   Expected Output: Diameter: 12

Q46. Write a Kotlin program to create a class Person with properties name and age. Create a method to check if the person is a minor or adult.
   Input: name = "Emma", age = 17
   Expected Output: Emma is a minor

Q47. Write a Kotlin program to create a class Employee with properties name and salary. Create a method to display a salary report.
   Input: name = "Ethan", salary = 70000
   Expected Output: Ethan earns 70000

Q48. Write a Kotlin program to create a class Rectangle with properties length and width. Create a method to calculate the diagonal of the rectangle.
   Input: length = 9, width = 12
   Expected Output: 15

Q49. Write a Kotlin program to create a class Product with properties name, price, and quantity. Create a method to calculate the total cost.
   Input: name = "Shoes", price = 50, quantity = 3
   Expected Output: Total cost: 150

Q50. 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: 5.0

Share on Social Media