Loading...
Create a Parent-Child Inheritance Hierarchy
Design a Vehicle parent class with properties (brand, model, year) and methods (displayInfo()). Create two child classes: Car and Bike. Car should add numberOfDoors property, and Bike should add engineType property. Write a program that creates objects of both child classes and calls their methods.
Implement Different Types of Inheritance
Create a program demonstrating single inheritance with an Animal parent class and Dog child class. Then implement multi-level inheritance: Animal → Mammal → Dog. Also demonstrate multiple inheritance (if supported) or use interfaces to simulate it with an Employee class that implements both Payable and Taxable interfaces. Show how each type works with appropriate method overriding.
Practice Method Overriding and Polymorphism
Create a Shape parent class with calculateArea() method. Implement child classes: Circle, Rectangle, and Triangle. Each class should override calculateArea() with their specific formula. Demonstrate how polymorphism allows calling the same method on different object types.
Design and Implement an Abstract Class Hierarchy
Create an abstract class Animal with abstract methods makeSound() and move(). The class should also have a concrete method displayInfo() that prints the animal's name. Implement at least three concrete subclasses (e.g., Dog, Cat, Bird) that override the abstract methods. Create objects of each subclass and demonstrate polymorphism by calling methods on them through references of the abstract class type.
Create and Use Packages
Create a package structure for a simple project: com.myapp.utils and com.myapp.models. Define a utility class in the utils package with static methods for common operations (e.g., calculate factorial, check if prime). Define a model class (e.g., Student) in the models package. Import and use both classes in a main class located outside these packages, demonstrating proper package naming and access.
Implement and Use Interfaces
Design an interface PaymentProcessor with methods processPayment() and refund(). Implement this interface with two concrete classes: CreditCardProcessor and PayPalProcessor. Each implementation should have different logic. Create a program that accepts payment method as input and processes a payment using the appropriate implementation, demonstrating interface polymorphism.
Basic Lambda Expressions with Functional Interfaces
Create functional interfaces Calculator (add operation). Write lambda expressions to implement that interface.
Lambda with Collections and Streams
Create a list of integers and use lambda expressions with stream operations to: filter numbers greater than 10.