Question Bank - OOPS
Question Bank - OOPS
Unit – I
Short Answer Questions:
Unit – II
Short Answer Questions :
1. Write a Java program that will return the first half of the string, if the length of the
string is even. It should return null if the length of the string is odd.
2. Write a program to receive an integer number as a command line argument, and print
the binary, octal, and hexadecimal equivalent of the given number.
3. Differentiate between static and run-time polymorphism with an example.
4. List out the differences between “abstract class” and “interface”.
5. What is a marker interface? List out any two marker interfaces.
6. Differentiate between “implements” and “extends” keywords.
7. What are the steps involved to create and import a package ?
8. Explain the difference between length and length() with suitable example.
Long Answer Questions :
1. What is the role of the constructor? Explain constructor overloading with an example .
2. Define static data member in Java and demonstrate a suitable example to count the
number of objects constructed using static data members.
3. Explain any three usages of “this” keyword with an example of each.
4. What is method overloading in Java? Write a program to overload area() method, which
will calculate the area of a rectangle and square.
5. Create a class called Calculator with the following methods: 1) A static method called
powerInt(int num1,int num2) This method should return num1 to the power num2. 2)
A static method called powerDouble(double num1,int num2). This method should
return num1 to the power num2. Invoke both methods and test the functionalities.
6. Write a program to create a base class Fruit with name, taste, and size as its attributes.
Create a method called eat() which describes the name of the fruit and its taste. Inherit
the same in 2 other classes Apple and Orange and override the eat() method to represent
each fruit taste.
7. Demonstrate “Autoboxing” and “Unboxing” with suitable examples.
8. Explain the concept of “Dynamic method dispatch” with a suitable example.
9. List out all the usages of super keyword with suitable example.
10. Write a program to read an input String from the user and parse it to an integer, if it is
not a number it will throw NumberFormatException, Catch it, and print "Entered input
is not a valid format for an integer." or else print the square of that number
11. Explain the working principle of “nested try-catch” with a suitable example.
12. Write a program to create a package called test package. Define a class called
foundation inside the test package. Inside the class, you need to define 4 integer
variables: var1 with private access modifier, var2 with default access modifier, var3
with protected access modifier, var4 with public access modifier. Import this class and
packages in another class. Try to access all 4 variables of the foundation class and see
what variables are accessible and what are not accessible.
13. Explain the following with an example: i) super ii) final
14. What is the difference between an Error and an exception? Write a Java program to
illustrate the usage of multiple catch handlers.
15. Differentiate between String and StringBuffer class. Write a program to test whether a
string is palindrome or not.
16. Explain the following methods used in SringBuffer class with examples.
i)append()
ii) insert()
iii) replace()
iv) delete()
v) length()
17. Write a Java Program to Find the Frequency of Character in a String.
18. What is multiple inheritance? How can we achieve multiple inheritance in Java, explain
with an example.
Unit – III
Short Answer Questions :
1. Write a program to create a thread that prints 1 to 10. After printing 5, there should be
a delay of 5000 milliseconds before printing 6.
2. Explain the role of wait(), notify() and notifyAll() methods?
3. What is a thread scheduler, and how is it related to thread priority?
4. Explain the need for “static synchronization” in multithreading.
5. What is a daemon thread? How do you create a daemon thread in Java?
6. Write down the syntax to open a file in reading mode. List out the possible exceptions.
7. How many ways a thread can be created? Explain with and example.
8. Write a program to read a sentence and display it by inserting * in place of space.
Long Answer Questions :
1. Write a program to create two threads, one thread to display all even numbers between
1 & 20, and another thread to display odd numbers between 1 & 20. Note: Display all
even numbers followed by odd numbers.
2. Differentiate among sleep(), yield(), and join() method.
3. Create a class called Employee with properties name(String), department(String),
designation(String), and Salary(double). Create respective getter and setter methods
and constructors (no-argument constructor and parameterized constructor) for the
same. Create an object of the Employee class and save this object in a file called "data"
using serialization. Later using deserialization read this object and print the properties
of this object.
4. Explain the life cycle of a thread with a neat diagram.
5. What is the significance of the “anonymous inner class” ? Explain with an example.
6. Write a program to copy the contents of a file “source.txt” into “destination.txt”. ( Note:
All possible exceptions should be handled.)
7. What is synchronization? Explain the role synchronized method with a suitable
example.
8. Explain the role of InputStream and OutputStream classes. Write a program to count
the total characters present in a file (excluding the spaces).
9. Write down the syntax of nested try block. Explain with suitable example by using
exception classes ArithmeticException and ArrayIndexOutOfBoundsException.
10. Explain thread priorities with a suitable example.
11. What do you mean by deadlock? Explain with an example.
12. What is user user-defined Exception in Java? WAP to accept student age and check
whether he is eligible to vote or not? Show an appropriate message when the age is not
eligible.
Unit – IV
Short Answer Questions :
1. Describe the methods (1) setBackground( ) (2) setForeground( ) with their syntax.
2. Differentiate between “applet” and “application”.
3. What is the advantage of “Adapter” class over “Listener” interface?
4. What is the difference between the paint() and init() method?
5. Write down the syntax and usage of setBounds() and setSize() method in AWT.
6. Explain the role of the Frame class in AWT programming.
7. Write a program to display “Hello Friend” using an applet.
8. Write a program to set parameter using applet and display the values of parameters
using an applet.
9. What is the difference between “getDocumentBase()” and “getCodeBase()” method.
10. List out any four methods (along with syntax and usage) of Graphics class.
11. List out the basic differences between checkbox and radio button. Write down the steps
to create three checkboxes (CSE,CST,CSA) and two radio buttons (MALE,FEMALE).
Long Answer Questions :