Core Java Unit 2:
Objects and Classes
Easy Level Questions ( 5 Marks Each)
(Bloom’s Taxonomy:
Remembering, Understanding)
1.
What is a class in
Java? How does it differ from an object?
2.
List the four access specifiers available in Java. Briefly state the visibility
scope of public
and private
members.
3.
Explain the purpose of
a constructor in Java. Can a class have more than one constructor?
4.
What is the this
keyword used for in Java? Give a simple example.
5.
Differentiate between a
static variable and an instance variable in a Java class.
6.
Explain the function of
the toString() method, inherited from the Object class. Why is it often overridden?
7.
What are Wrapper
Classes in Java? Give two examples and their corresponding primitive types.
Moderate Level Questions (5
Marks Each)
(Bloom’s Taxonomy:
Understanding, Applying, Analyzing)
8.
Describe the concept of
"defining user-defined classes" with respect to real-world entities.
Provide a Java code snippet for a simple Student class including relevant attributes (e.g., name, rollNo).
9.
Compare and contrast
the protected
and default
(package-private) access specifiers in Java. Provide
a scenario where protected would be preferred over default.
10.
Write a Java program to
create an Array of Objects for the Student class defined in Question 8. Store details for three
students and then display their information.
11.
Explain
"Constructor Overloading" with a suitable Java example. Demonstrate
how different constructors can be used to initialize an object in various ways.
12.
Discuss two distinct
uses of the this
keyword in Java with illustrative code examples for each.
13.
Explain the concept of
a "Static Block" in Java. When is a static block executed, and what
is its typical use? Provide a code example.
14.
What are Inner Classes
in Java? Briefly describe two common types of inner classes (e.g., Member Inner
Class, Anonymous Inner Class) and when you might use them.
15.
Describe the process of
"Creating, Accessing, and Using Packages" in Java. Explain the role
of the package
keyword and the import statement. Provide an example of how you would structure a
simple project with two packages.
16.
Explain why Wrapper
Classes are necessary in Java, especially when working with collections.
Difficult Level Questions (5
Marks Each)
(Bloom’s Taxonomy: Analyzing, Evaluating, Creating)
18.
Design a Java class
called Book
with attributes title,
author,
isbn, and price (double). Implement the following:
o A parameterized constructor.
o A method displayBookDetails() that prints all book information.
o Override equals() and hashCode() such that two books are considered equal if their isbn is identical.
o Override toString() to return a user-friendly string representation of the
book.
o Demonstrate the creation of an Array
of Objects of type Book, add some books, and use the equals() method to check for duplicate books based on isbn.
19.
Evaluate the role of static methods and static fields in designing utility classes (e.g., Math class). Compare the use of static members with instance members in terms of memory
management and accessibility. Under what circumstances would you strictly avoid
making a method static? Provide justifications.