Rungta International Skill University, Bhilai
School of Computer Science and Engineering
Object Oriented Programming With Java - Practice Set
Duration: 2:00 hrs Max. Marks: 110
Prepared in the style and format of the uploaded paper.
Section A – MCQs (10 × 1 = 10 Marks)
1. What will be the default value of elements in a boolean array in Java?
A) true
B) false
C) null
D) 0
2. Which method is used to compare the contents of two String objects in Java?
A) ==
B) compareTo()
C) equals()
D) hashCode()
3. What will be the output of the given code?
String s = "Java";
[Link]("Programming");
[Link](s);
A) JavaProgramming
B) Programming
C) Java
D) Compile-time Error
4. Which of the following statements about StringBuilder is TRUE?
A) Objects are immutable
B) It supports multithreading synchronization
C) It is mutable
D) It belongs to [Link] package
5. Which keyword is used to achieve inheritance in Java?
A) implement
B) inherit
C) extends
D) super
6. Which of the following is an example of Upcasting?
A) Dog d = new Animal();
B) Animal a = new Dog();
C) Dog d = (Dog)new Animal();
D) Animal a = Animal();
7. What will getClass() return in Java?
A) Memory address of object
B) Name of constructor
C) Runtime class information of object
D) Hash value of object
8. Which method is automatically available in every Java class through Object class?
A) display()
B) main()
C) show()
D) toString()
9. Which principle of OOP hides internal implementation details from users?
A) Polymorphism
B) Inheritance
C) Data Hiding
D) Abstraction
10. What will be the output of the following code?
StringBuilder sb = new StringBuilder("Code");
[Link]("Lab");
[Link](sb);
A) Code
B) Lab
C) CodeLab
D) Compile-time Error
Section B – Answer any Fifteen Questions (15 × 4 = 60 Marks)
1. What is an Array in Java? Explain different ways of declaring and initializing arrays with
suitable examples.
2. Write a Java program to find the largest element present in an integer array.
3. Differentiate between String and StringBuilder in Java with suitable examples.
4. Write a Java program to reverse a string without using built-in reverse methods.
5. What is Encapsulation? Explain how getters and setters help in achieving encapsulation.
6. Write a Java class Employee with private data members empId, name, and salary. Use
setter and getter methods to access them.
7. What is Data Hiding? Explain its advantages in object-oriented programming.
8. Write a Java program to count the number of words present in a string entered by the
user.
9. Explain constructor chaining using this() with a suitable example program.
10. What is Inheritance in Java? Explain Single Inheritance using a suitable example.
11. Differentiate between Method Overloading and Method Overriding.
12. What is Runtime Polymorphism? Explain with a suitable Java program.
13. Explain Upcasting and Downcasting in Java with suitable examples.
14. What is the purpose of toString() method in Java? Explain with an example.
15. Differentiate between == operator and .equals() method in Java.
16. What is the use of hashCode() method in Java? Explain with a suitable example.
17. Write a Java program to check whether a given string is a palindrome or not.
18. Explain Hierarchical Inheritance with a suitable example.
19. What is getClass() method in Java? Explain its use with a suitable example.
20. Write a Java program using StringBuilder to concatenate two strings entered by the
user.
Section C – Answer any Fifteen Questions (15 × 10 = 150 Marks)
1. Explain Arrays in Java. Discuss one-dimensional arrays, two-dimensional arrays, and
Jagged Arrays with suitable example programs.
2. Write a Java program to store marks of 5 students in an array and display the highest,
lowest, and average marks.
3. What are Strings in Java? Explain String immutability and the concept of String Constant
Pool with suitable examples.
4. Differentiate between String, StringBuilder, and StringBuffer with suitable coding
examples.
5. Write a Java program to perform the following operations on a string: Count vowels and
consonants, convert to uppercase, and reverse the string.
6. What is Encapsulation? Explain how encapsulation improves security and maintainability
of programs. Create a suitable Java class example.
7. Write a Java program to create a class BankAccount with private data members account
number, holder name, and balance. Provide suitable getter and setter methods with
validation.
8. Explain the difference between Data Hiding and Encapsulation with real-life examples.
9. What is Inheritance in Java? Explain Single, Multilevel, and Hierarchical inheritance with
suitable coding examples.
10. Why does Java not support Multiple Inheritance through classes? Explain how interfaces
help to achieve multiple inheritance.
11. Explain Compile-Time Polymorphism and Runtime Polymorphism with suitable Java
programs.
12. Write a Java program demonstrating method overriding using a base class Animal and
derived classes Dog and Cat.
13. Explain Upcasting and Downcasting in detail. Also discuss the role of instanceof
operator in safe downcasting.
14. What is Object class in Java? Explain the methods toString(), equals(), hashCode(), and
getClass() with suitable examples.
15. Write a Java program to create a class Student containing roll number, name, and marks.
Override toString() and equals() methods and demonstrate their working.
16. Explain the relationship between equals() and hashCode() methods in Java. Why is it
important to override both together?
17. Write a Java program to demonstrate polymorphism using upcasting where a parent
class reference is used to call overridden methods of child classes.
18. Explain the advantages and disadvantages of inheritance in Java with real-life examples.
19. Write a Java program to sort an array of strings alphabetically.
20. Create a Java class Book having private data members bookId, title, and price.
Implement constructors, getters, setters, and override toString() method to display object
details properly.