Interview challenge based on covered topics
OOP Concepts
-
Create a class
Car
: Define attributes likemake
,model
, andyear
, and include a method to display the car's details. Instantiate objects and display information for different cars. -
Design an Employee Management System: Create a base class
Employee
with properties likename
,ID
, andsalary
. Inherit from it to create aManager
class with additional properties likedepartment
. -
Library System: Create classes
Book
andMember
. TheBook
class should have attributes liketitle
andauthor
, and theMember
class should manage borrowing and returning books. -
Shape Hierarchy: Create a base class
Shape
with a methodcalculateArea()
. Derive classesCircle
,Rectangle
, andTriangle
fromShape
, and implement the area calculation in each derived class. -
Student Class: Design a
Student
class with attributes likename
,age
, andmarks
. Create a derived classGraduateStudent
that adds extra fields likethesis
and calculate the final grade based on marks. -
Account System: Implement a base class
Account
with basic methods for deposit and withdrawal. Create a derived classSavingsAccount
that implements interest calculation. -
Inheritance of Vehicles: Create a class
Vehicle
and derived classesCar
,Truck
, andMotorcycle
. Each derived class should implement a method that returns its fuel efficiency. -
Zoo Management System: Create an abstract class
Animal
with methodseat()
andsleep()
. Derive classesLion
,Elephant
, andGiraffe
that override these methods. -
Shape Drawing System: Create an abstract class
Shape
with a methoddraw()
. Inherit it in classesCircle
,Rectangle
, andTriangle
. Implement thedraw
method to display the shape in a 2D format. -
Employee Salary Calculator: Create a class
Employee
withname
,id
, andsalary
. Then, create aManager
class that inherits fromEmployee
and adds a method to calculate bonus.
If-Else Concepts
-
Odd or Even: Write a program that takes an integer as input and checks if it is odd or even using if-else statements.
-
Grade Calculator: Write a program that takes a student’s marks as input and prints the grade (A, B, C, D, F) based on the range of marks using if-else.
-
Leap Year Checker: Write a program to check if a given year is a leap year or not using if-else conditions.
-
Simple ATM: Simulate an ATM system where the user is prompted to enter their pin. Use if-else statements to check if the pin matches the stored value. If it matches, allow the user to withdraw money, else deny access.
-
Age Category: Write a program that checks if a person is a child, teenager, or adult based on their age using nested if-else statements.
Basic Java String
-
Palindrome Checker: Write a program that takes a string as input and checks if it’s a palindrome or not.
-
String Reverse: Write a program to reverse a string entered by the user without using built-in methods like
reverse()
. -
Count Vowels and Consonants: Write a program that counts the number of vowels and consonants in a given string.
-
Character Frequency: Write a program that takes a string and a character as input and counts how many times the character appears in the string.
-
String Concatenation: Write a program that takes two strings as input and prints the concatenated string without using the
+
operator.
Array-Based Challenges
-
Find Maximum in Array: Write a program that finds the largest number in an array using loops.
-
Array Sum: Write a program that takes an array of integers as input and returns the sum of all the elements.
-
Reverse an Array: Write a program to reverse the elements of an array without using built-in methods.
-
Find Missing Number in Array: Given an array of integers from 1 to N, write a program to find the missing number using an array.
-
Array Rotation: Write a program that rotates an array to the right by
k
positions. -
Duplicate Elements in Array: Write a program that finds and displays all the duplicate elements in an array.
-
Find Second Largest in Array: Write a program to find the second-largest number in an unsorted array.
-
Merge Two Arrays: Write a program to merge two arrays of integers into one sorted array.
-
Check for Array Symmetry: Write a program that checks whether an array is symmetric (i.e., it reads the same forward and backward).
-
Array Intersection: Write a program that finds the intersection of two arrays (i.e., elements that are common to both arrays).
Comments
Post a Comment