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
Employeewith properties likename,ID, andsalary. Inherit from it to create aManagerclass with additional properties likedepartment. -
Library System: Create classes
BookandMember. TheBookclass should have attributes liketitleandauthor, and theMemberclass should manage borrowing and returning books. -
Shape Hierarchy: Create a base class
Shapewith a methodcalculateArea(). Derive classesCircle,Rectangle, andTrianglefromShape, and implement the area calculation in each derived class. -
Student Class: Design a
Studentclass with attributes likename,age, andmarks. Create a derived classGraduateStudentthat adds extra fields likethesisand calculate the final grade based on marks. -
Account System: Implement a base class
Accountwith basic methods for deposit and withdrawal. Create a derived classSavingsAccountthat implements interest calculation. -
Inheritance of Vehicles: Create a class
Vehicleand derived classesCar,Truck, andMotorcycle. Each derived class should implement a method that returns its fuel efficiency. -
Zoo Management System: Create an abstract class
Animalwith methodseat()andsleep(). Derive classesLion,Elephant, andGiraffethat override these methods. -
Shape Drawing System: Create an abstract class
Shapewith a methoddraw(). Inherit it in classesCircle,Rectangle, andTriangle. Implement thedrawmethod to display the shape in a 2D format. -
Employee Salary Calculator: Create a class
Employeewithname,id, andsalary. Then, create aManagerclass that inherits fromEmployeeand 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
kpositions. -
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