Test Your Knowledge With Java Quiz Questions and Answers for Beginners
Java Quiz Questions & Answers
1. What is the difference between a checked and an unchecked exception?
A checked exception is a subclass of Exception which must be caught either at the time of compilation or during execution, while an unchecked exception is a subclass of RuntimeException and doesn’t need to be caught in the code.
2. What is the purpose of the java final keyword?
The Java final keyword can be used for different purposes such as making a variable constant, making a class immutable, making a method non-overridable and making a class non-inheritable.
3. What is the purpose of the static keyword in Java?
The static keyword is used for declaring a class member that can be accessed without creating an instance of the class. It can be used for variables, methods, and blocks.
4. What are packages in Java?
Packages are a way of grouping related classes, interfaces, and sub-packages together in Java. Packages help organize and structure the code, providing better namespace management and making classes easier to find and use.
5. What is the difference between a constructor and a method in Java?
A constructor is a special method that is called when an object of the class is created. It is used to initialize the state of the object. A method is a procedure or function associated with a class to perform a specific task.