Jawaharlal Nehru Technological University Hyderabad
Jawaharlal Nehru Technological University Hyderabad B.Tech II Year OBJECT ORIENTED PROGRAMMING THROUGH JAVA Previous Question Paper (September - 2021 - R16)
Answer any five questions. All questions carry equal marks.
Main
Write a program to implement multilevel hierarchy, use super keyword to define methods in sub classes.
Answer
Multilevel inheritance in Java is a process where a class is derived from a class which is also derived from another class, i.e., a class has more than one parent class. The super keyword is a reference variable used to refer to the immediate parent class object, allowing subclasses to invoke overridden methods or access hidden members of the superclass.
The following program demonstrates a three-level hierarchy: Grandparent → Parent → Child.
class Grandparent {
void display() {
System.out.println("Grandparent class method");
}
}
class Parent extends Grandparent {
void display() {
super.display(); // Invoking Grandparent method
System.out.println("Parent class method");
}
}
class Child extends Parent {
void display() {
super.display(); // Invoking Parent method
System.out.println("Child class method");
}
}
public class MultilevelDemo {
public static void main(String[] args) {
Child obj = new Child();
obj.display();
}
}Key Concepts:
- Inheritance Hierarchy: The
Childclass inherits properties fromParent, which in turn inherits fromGrandparent. - Method Overriding: Each class provides a specific implementation of the
display()method. - Super Keyword: Used within the
display()method of the subclass to explicitly call the overridden method of the immediate superclass, ensuring that the entire chain of execution is maintained. - Execution Flow: When
obj.display()is called, theChildclass invokessuper.display(), which triggers theParentclass method, which then triggers theGrandparentclass method, resulting in a sequential output of all three levels.
How is abstraction different from information hiding?
Answer
- Abstraction is a design-level technique that focuses on the essential characteristics of an object, ignoring irrelevant details. It provides a simplified view of a system by defining a clear interface, allowing the user to interact with the object without needing to understand its internal implementation.
- Information Hiding is an implementation-level strategy that restricts access to the internal state and data of an object. It ensures that the internal representation of an object is protected from unauthorized or accidental modification by external entities.
- Key Differences:
- Abstraction is about what an object does (the interface), whereas information hiding is about how it achieves its functionality (the implementation).
- Abstraction reduces complexity by providing a high-level model; information hiding increases security and maintainability by enforcing encapsulation.
- Abstraction is often achieved through abstract classes and interfaces, while information hiding is primarily achieved using access modifiers (private, protected).
What features of Java make it a robust language?
Answer
Sign in to view the complete answer paper.
Write a program to merge the content of two files (user’s contacts in a mobile) into a target file.
Answer
Sign in to view the complete answer paper.
Discuss access protection for packages.
Answer
Sign in to view the complete answer paper.
How to inherit an interface to another?
Answer
Sign in to view the complete answer paper.
Describe the life cycle of a thread.
Answer
Sign in to view the complete answer paper.
How to assign priorities to threads in Java program?
Answer
Sign in to view the complete answer paper.
What is an exception? How is it different from an error? What are the basic keywords used to handle exceptions in Java? Explain their usage.
Answer
Sign in to view the complete answer paper.
How to obtain an array from an ArrayList?
Answer
Sign in to view the complete answer paper.
What steps need to be followed to use an iterator to cycle through the contents of a collection?
Answer
Sign in to view the complete answer paper.
Create a user interface using MVC architecture and swing concepts to book a seat in a bus [like redbus/abhibus applications].
Answer
Sign in to view the complete answer paper.