Java Beginner Questions 2
Java Beginner Questions 2
1. Create a class 'Person' with attributes name and age. Create a method to display the
details.
2. Implement a class 'BankAccount' with methods for deposit, withdraw, and checking the
balance.
3. Define a class 'Rectangle' with width and height. Add a method to calculate the area.
5. Create a class hierarchy with 'Animal' as a base class and 'Dog' and 'Cat' as derived
classes.
7. Implement method overriding by creating a parent class 'Vehicle' and a subclass 'Car'.
9. Create a singleton class 'DatabaseConnection' that ensures only one instance is created.
10. Implement a deep copy mechanism in a 'Book' class using the Cloneable interface.
11. Create a class 'Employee' with private fields. Use getter and setter methods to access
them.
12. Demonstrate the use of the 'final' keyword with variables, methods, and classes.
13. Create a polymorphic behavior using an interface 'Playable' and implement it in multiple
classes.
15. Create a class that demonstrates the use of static variables and static methods.
16. Create a Java program where two threads print even and odd numbers up to 10
alternately.
17. Implement a multithreaded program where multiple threads increment a shared counter.
18. Create a Java thread by extending the Thread class and another by implementing
Runnable.
19. Implement a producer-consumer problem using wait() and notify() in Java.
21. Create a package 'utilities' with a class 'Calculator' that provides basic arithmetic
methods.
22. Implement a Java program that imports and uses a user-defined package.
23. Demonstrate how to access a class from a different package using import statements.
24. Create a package with multiple related classes and use them in a main program.
27. Create a simple Observer pattern example where multiple observers react to a state
change.
28. Demonstrate the use of an inner class inside an outer class in Java.
30. Implement a custom exception class and demonstrate its usage in a program.