Siddaganga Institute of technology, Tumkur
Department of computer Science and Engineering
Third Semester 2025-26
Java Questions Bank
1. a) Develop a Java program to demonstrate method overloading and constructor
overloading.
b) Justify the role of final keyword i) with respect to the data members
ii) with respect to the derived class. Give one example for each
c) What is the role of Garbage Collector? How it is supported by Java? What is the
role of finalize() method?
2. a) Develop a Java program to print factorial of a given number using recursion.
b) Design a class CRICKET. Include data member's name, role (batsman, bowler or
all-rounder), include member functions to accept player details and to show player
details. Include multiple constructors.
c) Define the following: i) Object ii) Class iii) Constructor
3. a) Design a super class called Staff with details as Staffld, Name, Phone
and Salary. Extend this class by writing three subclasses namely
Teaching (domain, publications), Technical (skills) and Contract
(period). Write a Java program to read and display at least 3 staff objects
of all three categories.
b) What do you understand by the term inheritance? Mention the types of
inheritance and explain each of them in brief.
c) What is an abstract class? How it is useful in developing Java applications?
4. a) Design a class Animal, derive two classes Dog and Cow from
Animal. Include appropriate data members and member functions.
d) What is dynamic method dispatch in Java? How it is supported by Java?
Explain with an example.
e) How multi-level inheritance is supported by Java? Explain with an example.
5. a) What are exceptions? How exceptions are handled by Java? Give example.
f) Create two packages Pl and P2. In package Pl, create class A, class B
inherited from A, class C. In package P2, create class D inherited from
class A in package P1 and class E. Demonstrate working of access
modifiers (private, public,
protected, default) in all these classes using Java.
c) Can we have Nested try blocks while handling Exceptions? Explain with an
example.
6. a) How uncaught exceptions are caught? Give an example.
b) Give step by step procedure to create a Java package. Explain with an example.
c) Develop a Java program to read two integers a and b. Compute alb and print, when
b is not zero. Raise an exception when b is equal to zero. Also demonstrate
working of Array Index Out of Bound Exception.
7. a) What are constructors? Explain different types of constructor with example.
b) Develop java code using static member.
c) Discuss method overloading with an example.
8 a) What are garbage collectors? Explain with an example.
b) Explain use of “this” in Java.
c) Is Final is different from Finalize? Justify your answer with suitable example.
9 a) Explain different types of inheritance in Java.
b) Illustrate dynamic method dispatch using abstract class in Java.
c) Give an example for method overriding.
10 a) Explain the working of i) Final class ii) Final method
b) How multilevel inheritance is supported by Java? Explain with a suitable example.
c) What is an abstract class? Explain with example.
11 a) Why interfaces? Explain interfaces in Java with suitable example.
b) What is the role of package in java? Create a Java package and explain how it is used in java program.
12 a) what is an exception? With example demonstrate different mechanisms used for handling exceptions
in Java.
b) What are uncaught exceptions? How to create our own exceptions. Explain with the program.
13 a) Explain overloading. Give a Java program for overloading constructors.
b) Discuss how to resolve any namespace collision that might occur between instance variables and local
variables.
c) Explain garbage collection used in Java.
14 a) Differentiate between static data members and methods. Explain several restrictions on static
methods.
b) Develop Java code to create objects of type Box with Width, Height, and depth as data members.
Compare any two objects by passing the object as the parameter.
c) Give the Java program to demonstrate the difference between public and private access specifiers.
15 a) With an example explain the uses of the super keyword.
b) Differentiate method overloading from overriding with example.
c) Explain the dynamic method dispatch used in Java with an example.
16 a) Explain with an example abstract class in Java.
b) Brief the uses of the final keyword with inheritance in Java.
c) With an example explain multilevel inheritance supported in Java.
17 a) Define the interface and its implementation in Java.
b) Create a Java package balance and demonstrate how it is used in Java programs.
c) Explain multiple catch clauses and finally block in Java. Give an example.
18 a) Explain with an example how an interface can be extended.
b) Explain exception class hierarchy in Java.
c) Differentiate between throw and throws key words used in exception.
19. Write a Java program to do the following.
i. Create an Account class
ii. Create two derived classes for Account class, namely SavingsAccount and CurrentAccount
iii. Create a BankClass, which has an array of Account objects
iv. Create an update method in the BankClass, which gives 8% interest to SavingsAccounts and 6% interest
to CurrentAccount.
20. What is constructor? Explain different types of constructors in Java.
21. Explain garbage collection in Java.
22. Describe the concept of method overloading and method overriding with an example program.
23. Explain the various usages of super keyword in Java.
24. Explain the uses of final and this keywords in Java.
25. Explain, how the runtime errors are handled in Java?
26. Explain, how multiple inheritance is achieved in Java?
27. Explain any two built in exceptions with an example program.
28. Create a base class called Shape, it contains two methods getxyvalue( ) and showxyvalue( )
for accepting coordinates and displaying coordinates. Create subclass called Rectangle. Apply overriding
concept to display length and breadth of rectangle.
29. Compare and contrast the following: i) Interface and class ii) Interface and abstract class.
30. Develop a class Teacher contains two fields, Name and [Link] the class to Department, it
contains Dept. No and Dept. Name. An interface named as College contains one field Name of the
[Link] above classes and interface get the appropriate information and display it.
31. What is package? What is the difference between implicit and explicit import statement?
32. Write a package called Clear, it contains one public method clrscr( ) to clear the screen, import the
package and use it in another programs. Add another public method starline( ). It prints the line of 15 stars.
33. Write a program for user defined exception that checks the internal and external marks; if the internal
marks are greater than 40 it raises the exception “Internal Marks is Exceed”; if the external marks in greater
than 60 it raises the exception and displays the message “The External Marks is Exceed”. Create the above
exception and use it in your program.
34. Define an exception called “No Match Exception” that is thrown when a string is not equal to “SIT”.
Write a program that use of exception handling.
35. Develop a Java program to implement multiple inheritance in calculating the area of square, rectangle
and triangle.
36. Mention any four built-in packages along with built-in class which belongs to respective package.
Develop a Java program to check whether the given number is prime or not using packages. (use two
classes).
37. Create a java class called student with the following variables.
i) USN ii) NAME iii) BRANCH iv) PHONE v) PERCENTAGE.
Write a JAVA program to create „n‟ student objects and print all the variables of each object with suitable
headings.
38. Develop a super class called STAFF with variables staff_id, Name, Phone, and salary.
Extend this class by writing three subclasses namely teaching (domain, publications) technical (skills) and
contract (period). Write a Java program to read and display a java program to read and display atleast 2 staff
objects of all three categories.
39. Explain the following: i) Defining an Interface ii) Implementing Interface iii) Nested Interfaces iv)
Extending Interfaces Through sample Java codes.
40. Briefly explain the role of Print writer class.