OOPS WITH JAVA — SYLLABUS-WISE QUESTION
BANK ORGANIZATION
Questions extracted ONLY from the provided JAVA QUESTION BANK PDF and reorganized carefully
according to the official syllabus modules.
MODULE I — INTRODUCTION TO OOP +
INTRODUCTION TO JAVA
OOP Concepts
1. In Java, encapsulation is achieved by bundling data and methods to operate as a single unit called
class - Explain with example.
2. What are the key differences between function overloading and function overriding in Java?
3. Explain method overloading and method overriding in Java with examples.
4. Describe the distinction between an abstract class and an interface in Java, providing examples for
clarity.
5. Define the terms abstract classes and interfaces. What are the similarities and differences between
abstract classes and interfaces?
6. Which object-oriented paradigm concept is/are satisfied using an abstract class?
7. Discuss how inheritance enhances code reusability in Java. Illustrate this with an example where
inheritance is utilized in a Java program to reuse existing code.
8. What is inheritance? Give an example using extends.
9. Create a Vehicle class with brand and year. Extend it to a Car class with an additional attribute model.
10. Write a code to display runtime polymorphism in Java.
11. How do you implement compile-time polymorphism in Java?
12. What is Java’s solution to multiple inheritance?
13. Is it possible in Java to implement multiple inheritance? Explain with an example how a derived class
can inherit from more than one base classes.
14. What are the advantages of using Inner Class in Java?
15. What is the difference between nested and inner class in Java?
16. What is the difference between static and non-static nested class in Java?
17. State the differences between Inner Class and Static Nested class.
18. What are the types of nested classes in Java? Explain briefly with examples.
19. Explain why Java is both portable and secure.
20. Name the parent class of all the classes in Java.
21. Write a method that takes two integers and returns their sum.
Introduction to Java
1. Explain the working of the Java Virtual Machine (JVM) and how it contributes to the portability of Java
applications.
1
2. What role does JVM play to make Java a platform independent language?
3. Is the Java compiler platform-independent? Justify your answer.
4. Compare Java's primitive data types with reference data types.
5. Explain the concept of Garbage Collection and its importance in memory management in Java.
6. Is it recommended to manually invoke the garbage collector, or should we rely solely on automatic
garbage collection?
7. "Java does not support destructors" — Justify the statement. How Java handles memory de-
allocation?
8. Is there any concept of destructor in Java? If yes, write the syntax to declare it. If not, how do you
think memory is deallocated in Java?
9. What is the job of the finalize method? When is a finalize block executed?
10. What is the difference between String and StringBuffer class?
11. Explain with an example code that Java strings are immutable.
12. In which Java package String class is defined?
13. Write a Java program to check whether a given string is a palindrome or not.
14. Discuss how command-line arguments are handled in Java. Provide an example program that takes a
list of numbers as command-line arguments and calculates their sum.
15. Give example of Java command line argument handling.
16. User first enters 5 numbers using command line argument. The program asks the user to enter a
number to search. If the number is found then the program prints the number of times it occurs in
the list of 5 numbers. Else, if the number is not found it prints "not found".
17. Say a Java program named [Link] is compiled and there is only one public class named Test
containing public static void main. What will it generate? How to run the program with command line
arguments? Where are the command line arguments stored?
18. Name the functions to take an integer, one word, and one line input from the user using Scanner
class.
19. Write a Java program to convert a String to an int and handle NumberFormatException.
20. What is the output of [Link](10 + 20 + "30");?
21. What is the difference between int and double in Java?
22. Write a program to find the largest element in an array.
23. Write a program to reverse an array in place (without using an extra array).
24. Write a program that takes 5 numbers from the user and calculates their average.
25. Print the first 10 Fibonacci numbers using a for loop.
26. Write a method to check if a number is prime and return true or false.
27. Write a program to check if a number is even or odd using an if-else statement.
28. Write a program to swap two numbers without using a temporary variable.
MODULE II — CLASSES, OBJECTS AND INHERITANCE
Classes and Objects
1. What are constructors? What is meant by constructor overloading? Explain with an example in Java.
2. Explain the purpose of a constructor in Java. Is it possible for a constructor to be private in Java?
Support your explanation with an example.
3. What is a constructor? How is it different from a method?
2
4. Create a Rectangle class with length and width as attributes. Write a parameterized constructor to
initialize them.
5. Create a Student class with name and rollNo as attributes. Create an object and print its details.
6. Add a method displayDetails() in the Student class to print name and roll number.
7. What are the uses of the static keyword in Java?
8. Create a class Counter with a static variable count that increments every time an object is created.
9. Describe the process of object creation in Java using the new keyword. What happens behind the
scenes when an object is created in Java?
10. Briefly explain the use of "this" and "super" keywords.
11. What is the keyword "this" used for in Java? Give an example.
12. What are the different uses of the keyword super in Java? Explain with an example.
13. What is the purpose of the super keyword in Java? Provide an example to demonstrate the use of the
super keyword.
14. In Java, what are the key differences between public, protected, and default (no specifier) access
specifiers?
15. What is the difference of use of default and protected access specifier?
16. What are the uses of finally block in Java?
17. What is the use of the keyword final when used with: (a) Class, (b) Method, (c) Variable.
18. What are the differences between final, finally, and finalize in Java?
19. Provide examples demonstrating the use of final, finally, and finalize keywords in Java.
20. Please justify the statement: "Abstract classes cannot be instantiated."
21. Can we instantiate an abstract class? If yes, write the syntax to do it. If no, explain your answer.
22. Why are abstract classes needed? What is the need of abstract methods in abstract class? Can
abstract class have objects?
23. What is an abstract method? How is it implemented in Java?
24. Write True or False: For a class in Java to be abstract, the class must contain an abstract method.
25. Write an example Java code showing the use of an abstract class. Also, write the output of the
program.
26. Abstract class shape has atleast one abstract method area(). Class rectangle and square extend class
shape. Write a program in Java for the above.
27. Class RBI has atleast one method interestRate(). Class HDFC and PNB inherit class RBI. Since they
each have their own interest rates they have their own implementation of the method interestRate().
Write a code in Java for the scenario and point out the instances of runtime polymorphism.
28. What is the job of the annotation @Override?
29. What will be the output of the given constructor chaining program involving Department and
thirdyear classes?
30. The given program involving complex class gives compilation error. Point out the error, explain the
reason and fix it.
31. What are the types of nested classes in Java? Explain briefly with examples. Can we access non-static
members of an outer class inside a static nested class?
32. The given Outer-Inner class code has two errors. Correct the code and instantiate Inner directly from
main.
33. What will be the output of the given program involving static nested class Inner and getSum()?
34. Create a Vehicle class and subclass Bus and Car with showData() methods.
35. Can you overload a method of a class in its subclass?
3
MODULE III — INTERFACES, GENERICS AND
PACKAGES
Interfaces
1. Write down the differences between interfaces and abstract classes.
2. Define the terms abstract classes and interfaces. What are the similarities and differences between
abstract classes and interfaces?
3. Describe the distinction between an abstract class and an interface in Java, providing examples for
clarity.
4. What is partial implementation of an interface?
5. With examples explain the scenario where the method in an interface can have a method body.
6. Can interface method have method body?
7. What are the cases when an interface can implement a method body?
8. interface vehicle { void caution(){ [Link]("Drive safe!"); } void speed(); } What is wrong in
the above interface? How can you rectify the mistake without changing any of the method
implementations?
9. Class car implements the above corrected interface. Access the methods speed and caution using
interface reference variable.
10. What is Java’s solution to multiple inheritance?
11. Is it possible in Java to implement multiple inheritance? Explain with an example how a derived class
can inherit from more than one base classes.
Generics
1. No direct major generics questions were present in the provided question bank.
Packages
1. What is package? How do we add a class or an interface to a package? What do you mean by
CLASSPATH?
2. What is package? What is the use of it? Why do we need import statement?
3. Explain the use of packages in Java.
4. Provide an example demonstrating how to create and use a package in a Java program.
5. Create a package shape containing classes Circle, Triangle and Rectangle. Every class of this package
should contain two methods, viz., area and perimeter.
4
MODULE IV — EXCEPTION HANDLING AND
MULTITHREADING
Exception Handling
1. How do we define try and catch block in Java?
2. How do we define try and catch block? Is it essential to catch all types of exceptions? Explain.
3. What are exceptions? Explain the user defined exceptions and system defined exceptions with
suitable examples.
4. Differentiate between checked and unchecked exceptions in Java.
5. Differentiate between checked and unchecked exception in Java. What is the use of finally() block?
6. What is the difference between throw and throws? Explain with example.
7. What is throw, throws? Explain with code. What is rethrow?
8. Explain when try, catch and finally are used.
9. Write the uses of finally block in Java.
10. Write the uses of finally block in Java. Write and explain the output of the given program.
11. Write a sample Java code to demonstrate ArrayIndexOutOfBoundsException, ArithmeticException
and NullPointerException exceptions.
12. Create two user defined exceptions viz. TooHot and TooCold. Write a Java program and throw TooHot
if the temperature exceeds 40 degrees and throw TooCold if the temperature is less than 20 degrees.
13. Write a Java program to convert a String to an int and handle NumberFormatException.
Multithreading
1. What is multithreading programming? Explain thread life cycle.
2. Explain the difference between creating a thread by extending the Thread class and creating a
thread by implementing the Runnable interface.
3. What are the two approaches of creating a thread in Java? Which approach do you prefer and why?
4. Mention the different states a thread can be in and give a brief description for each.
5. How can you obtain the state of a thread?
6. What do you mean by context switch with reference to Java threads and what are the rules that
determine when context switch will take place?
7. What is thread synchronization and why is it needed?
8. What are the similarities and differences between synchronized method and synchronized block in
Java thread?
9. Write an example Java program to implement thread communication using wait() and notify()
method.
10. Write a program in Java to print the name, priority and thread group of the thread. Change the name
of the current thread to "MyThread" and display the details.
11. What is the default name of the current executing thread? Write a program to change the name of
the current executing thread.
5
Swing/Applet/Event Handling (Extra Repeated Topics Present in
Question Bank)
1. Write a Java program to implement a JApplet to reverse letter cases.
2. Write a program in Java swing/applet to draw a polygon filled with green colour using RGB format.
3. Write a Java swing program which will accept two values in text boxes and display addition result in
third text box.
4. With example explain any two methods of JFrame, JLabel and JPanel in Java swing.
5. Explain how event delegation model works.
6. What is the event delegation model?
7. Write a program to explain event handling using Swing.
8. Explain how an event delegation model works. Write a Java program to pass a parameter to an
applet.