Practice 70 Java Interface Programming Questions, TechnoVlogs

Practice 70 Java Interface Programming Questions


Q1. Write a Java program to create an interface Animal with a method sound(). Implement it in classes Dog and Cat.  
Input: None  
Expected Output:  
Dog: Woof Woof  
Cat: Meow Meow  

Q2. Write a Java program to create an interface Vehicle with a method startEngine(). Implement it in classes Car and Bike.  
Input: None  
Expected Output:  
Car Engine Started  
Bike Engine Started  

Q3. Write a Java program to create an interface Shape with a method calculateArea(). Implement it in classes Rectangle and Triangle.  
Input:  
Rectangle: Length = 5, Width = 4  
Triangle: Base = 6, Height = 3  
Expected Output:  
Rectangle Area: 20  
Triangle Area: 9  

Q4. Write a Java program to create an interface Appliance with a method turnOn(). Implement it in classes Fan and Light.  
Input: None  
Expected Output:  
Fan Turned On  
Light Turned On  

Q5. Write a Java program to create an interface Payment with a method processPayment(). Implement it in classes CreditCard and PayPal.  
Input: None  
Expected Output:  
Payment Processed via CreditCard  
Payment Processed via PayPal  

Q6. Write a Java program to create an interface Bank with a method calculateInterest(). Implement it in classes HDFC and SBI.  
Input:  
HDFC: Principal = 10000, Rate = 5%, Time = 2 years  
SBI: Principal = 15000, Rate = 6%, Time = 3 years  
Expected Output:  
HDFC Interest: 1000  
SBI Interest: 2700  

Q7. Write a Java program to create an interface Sports with a method play(). Implement it in classes Cricket and Football.  
Input: None  
Expected Output:  
Playing Cricket  
Playing Football  

Q8. Write a Java program to create an interface Device with a method getSpecification(). Implement it in classes Mobile and Laptop.  
Input: None  
Expected Output:  
Mobile: 8GB RAM, 128GB Storage  
Laptop: 16GB RAM, 512GB SSD  

Q9. Write a Java program to create an interface Animal with a method habitat(). Implement it in classes Fish and Bird.  
Input: None  
Expected Output:  
Fish: Lives in water  
Bird: Lives on land  

Q10. Write a Java program to create an interface Calculator with a method add(). Implement it in classes SimpleCalculator and ScientificCalculator.  
Input:  
SimpleCalculator: 5 + 3  
ScientificCalculator: 12.5 + 7.5  
Expected Output:  
SimpleCalculator Result: 8  
ScientificCalculator Result: 20.0  

Q11. Write a Java program to create an interface Printer with a method printDocument(). Implement it in classes InkjetPrinter and LaserPrinter.  
Input: None  
Expected Output:  
InkjetPrinter: Printing document in color  
LaserPrinter: Printing document in black & white  

Q12. Write a Java program to create an interface Transport with a method travel(). Implement it in classes Train and Bus.  
Input: None  
Expected Output:  
Traveling by Train  
Traveling by Bus  

Q13. Write a Java program to create an interface Food with a method getCalories(). Implement it in classes Pizza and Salad.  
Input:  
Pizza: 300 calories per slice, 2 slices  
Salad: 50 calories per serving, 3 servings  
Expected Output:  
Pizza Calories: 600  
Salad Calories: 150  

Q14. Write a Java program to create an interface Account with a method deposit(). Implement it in classes SavingsAccount and CurrentAccount.  
Input:  
SavingsAccount: Deposit 10000  
CurrentAccount: Deposit 5000  
Expected Output:  
SavingsAccount Balance: 10000  
CurrentAccount Balance: 5000  

Q15. Write a Java program to create an interface Music with a method playSong(). Implement it in classes Guitar and Piano.  
Input: None  
Expected Output:  
Playing song on Guitar  
Playing song on Piano  

Q16. Write a Java program to create an interface Appliance with a method calculatePowerConsumption(). Implement it in classes WashingMachine and Microwave.  
Input:  
WashingMachine: 1.2kWh daily for 30 days  
Microwave: 0.8kWh daily for 30 days  
Expected Output:  
WashingMachine Power: 36kWh  
Microwave Power: 24kWh  

Q17. Write a Java program to create an interface Game with a method getRules(). Implement it in classes Chess and Carrom.  
Input: None  
Expected Output:  
Chess Rules: Two players, checkmate the opponent.  
Carrom Rules: Pocket coins and the queen.  

Q18. Write a Java program to create an interface Document with a method getFormat(). Implement it in classes PDF and WordDocument.  
Input: None  
Expected Output:  
PDF: Portable Document Format  
WordDocument: Microsoft Word  

Q19. Write a Java program to create an interface Toy with a method getType(). Implement it in classes CarToy and Doll.  
Input: None  
Expected Output:  
CarToy: Type is Remote Controlled  
Doll: Type is Soft Plush  

Q20. Write a Java program to create an interface Bank with a method withdraw(). Implement it in classes AxisBank and ICICIBank.  
Input:  
AxisBank: Withdraw 2000  
ICICIBank: Withdraw 1500  
Expected Output:  
AxisBank Balance: Updated after withdrawal  
ICICIBank Balance: Updated after withdrawal  

Q21. Write a Java program to create an interface Vehicle with a method fuelType(). Implement it in classes Truck and Scooter.  
Input: None  
Expected Output:  
Truck: Fuel Type is Diesel  
Scooter: Fuel Type is Petrol  

Q22. Write a Java program to create an interface Appliance with a method serviceRequired(). Implement it in classes Refrigerator and Oven. 
Input: None  
Expected Output:  
Refrigerator: Service Required Annually  
Oven: Service Required Biannually  

Q23. Write a Java program to create an interface Instrument with a method play(). Implement it in classes Violin and Drum.  
Input: None  
Expected Output:  
Violin: Playing Melodious Tune  
Drum: Playing Percussive Rhythm  

Q24. Write a Java program to create an interface Loan with a method calculateEMI(). Implement it in classes HomeLoan and CarLoan.  
Input:  
HomeLoan: Principal = 1000000, Rate = 7%, Time = 15 years  
CarLoan: Principal = 500000, Rate = 9%, Time = 5 years  
Expected Output:  
HomeLoan EMI: 8989  
CarLoan EMI: 10379  

Q25. Write a Java program to create an interface Gadget with a method getWarranty(). Implement it in classes Smartphone and Tablet.  
Input: None  
Expected Output:  
Smartphone: Warranty is 1 year  
Tablet: Warranty is 2 years  

Q26. Write a Java program to create an interface Animal with a method getDiet(). Implement it in classes Lion and Panda.  
Input: None  
Expected Output:  
Lion: Carnivore  
Panda: Herbivore  

Q27. Write a Java program to create an interface Payment with a method getTransactionFee(). Implement it in classes DebitCard and UPI.  
Input:  
DebitCard: Transaction of ₹5000  
UPI: Transaction of ₹3000  
Expected Output:  
DebitCard Fee: ₹50  
UPI Fee: ₹0  

Q28. Write a Java program to create an interface Building with a method getNumberOfFloors(). Implement it in classes Skyscraper and Bungalow.  
Input: None  
Expected Output:  
Skyscraper: 50 Floors  
Bungalow: 2 Floors  

Q29. Write a Java program to create an interface Shape with a method getPerimeter(). Implement it in classes Square and Circle.  
Input:  
Square: Side = 4  
Circle: Radius = 3  
Expected Output:  
Square Perimeter: 16  
Circle Perimeter: 18.84  

Q30. Write a Java program to create an interface Device with a method powerOff(). Implement it in classes Television and Router.  
Input: None  
Expected Output:  
Television: Powering Off  
Router: Powering Off  

Q31. Write a Java program to create an interface Tool with a method usage(). Implement it in classes Hammer and Screwdriver.  
Input: None  
Expected Output:  
Hammer: Used for driving nails  
Screwdriver: Used for tightening screws  

Q32. Write a Java program to create an interface Appliance with a method calculateLifetime(). Implement it in classes AirConditioner and WashingMachine.  
Input:  
AirConditioner: Lifetime = 10 years  
WashingMachine: Lifetime = 15 years  
Expected Output:  
AirConditioner Lifetime: 10 years  
WashingMachine Lifetime: 15 years  

Q33. Write a Java program to create an interface Person with a method getProfession(). Implement it in classes Teacher and Engineer.  
Input: None  
Expected Output:  
Teacher: Educator Profession  
Engineer: Technical Profession  

Q34. Write a Java program to create an interface Game with a method getWinner(). Implement it in classes Tennis and Badminton.  
Input:  
Tennis: Player A wins  
Badminton: Player B wins  
Expected Output:  
Tennis Winner: Player A  
Badminton Winner: Player B  

Q35. Write a Java program to create an interface Food with a method getIngredients(). Implement it in classes Cake and Pasta.  
Input: None  
Expected Output:  
Cake: Ingredients are Flour, Sugar, Eggs  
Pasta: Ingredients are Wheat, Sauce, Vegetables  

Q36. Write a Java program to create an interface Gadget with a method getOS(). Implement it in classes Smartwatch and Laptop.  
Input: None  
Expected Output:  
Smartwatch: OS is WearOS  
Laptop: OS is Windows  

Q37. Write a Java program to create an interface Employee with a method getWorkHours(). Implement it in classes PartTime and FullTime.  
Input: None  
Expected Output:  
PartTime: 20 hours per week  
FullTime: 40 hours per week  

Q38. Write a Java program to create an interface Vehicle with a method getMileage(). Implement it in classes ElectricCar and PetrolCar.  
Input:  
ElectricCar: 300km per charge  
PetrolCar: 15km per liter  
Expected Output:  
ElectricCar Mileage: 300km/charge  
PetrolCar Mileage: 15km/liter  

Q39. Write a Java program to create an interface Music with a method getGenre(). Implement it in classes RockBand and ClassicalSinger.  
Input: None  
Expected Output:  
RockBand: Genre is Rock  
ClassicalSinger: Genre is Classical  

Q40. Write a Java program to create an interface Animal with a method getScientificName(). Implement it in classes Horse and Tiger.  
Input: None  
Expected Output:  
Horse: Equus ferus caballus  
Tiger: Panthera tigris  

Q41. Write a Java program to create an interface Appliance with a method energyEfficiency(). Implement it in classes AirPurifier and Refrigerator.  
Input: None  
Expected Output:  
AirPurifier: Energy Efficient  
Refrigerator: Moderately Efficient  

Q42. Write a Java program to create an interface Account with a method getBalance(). Implement it in classes FixedDepositAccount and RecurringDepositAccount.  
Input: None  
Expected Output:  
FixedDepositAccount: Balance is ₹50000  
RecurringDepositAccount: Balance is ₹20000  

Q43. Write a Java program to create an interface Tool with a method maintenanceFrequency(). Implement it in classes PowerDrill and Saw.  
Input: None  
Expected Output:  
PowerDrill: Maintenance Every 6 Months  
Saw: Maintenance Annually  

Q44. Write a Java program to create an interface Person with a method introduce(). Implement it in classes Student and Professor.  
Input: None  
Expected Output:  
Student: I am a Student.  
Professor: I am a Professor.  

Q45. Write a Java program to create an interface Device with a method connect(). Implement it in classes BluetoothSpeaker and WiFiRouter. 
Input: None  
Expected Output:  
BluetoothSpeaker: Connected via Bluetooth  
WiFiRouter: Connected via Ethernet  

Q46. Write a Java program to create an interface Sports with a method getTeamSize(). Implement it in classes Basketball and Hockey.  
Input: None  
Expected Output:  
Basketball: Team Size is 5  
Hockey: Team Size is 11  

Q47. Write a Java program to create an interface Vehicle with a method topSpeed(). Implement it in classes SportsCar and Motorcycle.  
Input: None  
Expected Output:  
SportsCar: Top Speed is 200 mph  
Motorcycle: Top Speed is 150 mph  

Q48. Write a Java program to create an interface Book with a method getGenre(). Implement it in classes Fiction and Biography.  
Input: None  
Expected Output:  
Fiction: Genre is Adventure  
Biography: Genre is Historical  

Q49. Write a Java program to create an interface Gadget with a method batteryBackup(). Implement it in classes Smartphone and Laptop.  
Input: None  
Expected Output:  
Smartphone: Battery Backup is 24 Hours  
Laptop: Battery Backup is 8 Hours  

Q50. Write a Java program to create an interface Animal with a method reproduce(). Implement it in classes Oviparous and Viviparous.  
Input: None  
Expected Output:  
Oviparous: Reproduce by Laying Eggs  
Viviparous: Reproduce by Giving Birth  

Q51. Write a Java program to create an interface Shape with a method getVolume(). Implement it in classes Cube and Sphere.  
Input:  
Cube: Side = 3  
Sphere: Radius = 2  
Expected Output:  
Cube Volume: 27  
Sphere Volume: 33.51  

Q52. Write a Java program to create an interface Vehicle with a method getFuelCapacity(). Implement it in classes Truck and Sedan.  
Input: None  
Expected Output:  
Truck: Fuel Capacity is 200 liters  
Sedan: Fuel Capacity is 50 liters  

Q53. Write a Java program to create an interface Music with a method getDuration(). Implement it in classes Song and Podcast.  
Input: None  
Expected Output:  
Song: Duration is 4 minutes  
Podcast: Duration is 30 minutes  

Q54. Write a Java program to create an interface Device with a method checkBatteryLevel(). Implement it in classes Tablet and Smartwatch. 
Input: None  
Expected Output:  
Tablet: Battery Level is 80%  
Smartwatch: Battery Level is 60%  

Q55. Write a Java program to create an interface Transport with a method getFare(). Implement it in classes Cab and Metro.  
Input:  
Cab: Distance = 10 km, Rate = ₹15/km  
Metro: Distance = 10 km, Flat Rate = ₹20  
Expected Output:  
Cab Fare: ₹150  
Metro Fare: ₹20  

Q56. Write a Java program to create an interface Food with a method getPreparationTime(). Implement it in classes Burger and Pasta.  
Input: None  
Expected Output:  
Burger: Preparation Time is 10 minutes  
Pasta: Preparation Time is 15 minutes  

Q57. Write a Java program to create an interface Game with a method getScore(). Implement it in classes Basketball and Cricket.  
Input: None  
Expected Output:  
Basketball: Score is 85  
Cricket: Score is 220  

Q58. Write a Java program to create an interface Building with a method getAddress(). Implement it in classes Apartment and Office.  
Input: None  
Expected Output:  
Apartment: Address is 123 Main St.  
Office: Address is 456 Corporate Ave.  

Q59. Write a Java program to create an interface Payment with a method transactionLimit(). Implement it in classes CreditCard and DebitCard.  
Input: None  
Expected Output:  
CreditCard: Limit is ₹1,00,000  
DebitCard: Limit is ₹50,000  

Q60. Write a Java program to create an interface Instrument with a method material(). Implement it in classes Guitar and Flute.  
Input: None  
Expected Output:  
Guitar: Material is Wood  
Flute: Material is Metal  

Q61. Write a Java program to create an interface Payment with a method getPaymentMethod(). Implement it in classes CreditCardPayment and CashPayment.  
Input: None  
Expected Output:  
CreditCardPayment: Payment Method is Credit Card  
CashPayment: Payment Method is Cash  

Q62. Write a Java program to create an interface Artist with a method perform(). Implement it in classes Painter and Singer.  
Input: None  
Expected Output:  
Painter: Performing Art on Canvas  
Singer: Performing Song on Stage  

Q63. Write a Java program to create an interface Fruit with a method getTaste(). Implement it in classes Apple and Banana.  
Input: None  
Expected Output:  
Apple: Taste is Sweet  
Banana: Taste is Sweet  

Q64. Write a Java program to create an interface Shape with a method getDiagonal(). Implement it in classes Rectangle and Rhombus.  
Input:  
Rectangle: Length = 5, Width = 4  
Rhombus: Diagonal1 = 6, Diagonal2 = 8  
Expected Output:  
Rectangle Diagonal: 6.403  
Rhombus Diagonal: 7.211  

Q65. Write a Java program to create an interface Insurance with a method calculatePremium(). Implement it in classes HealthInsurance and LifeInsurance.  
Input:  
HealthInsurance: Age = 30, Coverage = ₹5L  
LifeInsurance: Age = 45, Coverage = ₹10L  
Expected Output:  
HealthInsurance Premium: ₹5000  
LifeInsurance Premium: ₹12000  

Q66. Write a Java program to create an interface Book with a method getPages(). Implement it in classes Novel and Textbook.  
Input:  
Novel: 350 pages  
Textbook: 700 pages  
Expected Output:  
Novel Pages: 350  
Textbook Pages: 700  

Q67. Write a Java program to create an interface Food with a method getCalories(). Implement it in classes IceCream and Burger.  
Input:  
IceCream: 200 calories per serving  
Burger: 300 calories per serving  
Expected Output:  
IceCream Calories: 200  
Burger Calories: 300  

Q68. Write a Java program to create an interface Payment with a method getTransactionStatus(). Implement it in classes DebitPayment and CreditPayment.  
Input:  
DebitPayment: Successful  
CreditPayment: Failed  
Expected Output:  
DebitPayment Status: Successful  
CreditPayment Status: Failed  

Q69. Write a Java program to create an interface Employee with a method getRole(). Implement it in classes Manager and Developer.  
Input: None  
Expected Output:  
Manager: Role is Manager  
Developer: Role is Developer  

Q70. Write a Java program to create an interface Vehicle with a method getEngineType(). Implement it in classes ElectricCar and DieselTruck.  
Input: None  
Expected Output:  
ElectricCar: Engine Type is Electric  
DieselTruck: Engine Type is Diesel  

Social Share

Bikki Singh Instructor TechnoVlogs

Bikki Singh

Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!