JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD MCA 2021 JAVA PROGRAMMING Previous Question Paper (July/August - 2021 - R13)
Answer any five questions. All questions carry equal marks.
Main
What object oriented features are supported by Java language? Briefly explain with suitable code segments.
Answer
Java is a robust object-oriented programming language that supports the four fundamental pillars of OOP, along with other essential features:
- Encapsulation: The mechanism of wrapping data (variables) and code (methods) together as a single unit. It restricts direct access to data using private access modifiers and provides public getter/setter methods.
private int age; public void setAge(int a) { age = a; } - Abstraction: The process of hiding complex implementation details and showing only the essential features of an object. This is achieved in Java using abstract classes and interfaces.
abstract class Shape { abstract void draw(); } - Inheritance: A mechanism where one class acquires the properties and behaviors of another class, promoting code reusability. Java supports single and multilevel inheritance through the extends keyword.
class Animal { void eat() {} } class Dog extends Animal {} - Polymorphism: The ability of an object to take on many forms. Java supports compile-time polymorphism (method overloading) and runtime polymorphism (method overriding).
// Overriding example: class Parent { void show() {} } class Child extends Parent { void show() {} }
Additionally, Java supports Classes and Objects as the basic building blocks, and Interfaces to achieve multiple inheritance of type, which is not supported through classes.
Write a program to demonstrate constructor overloading.
Answer
Constructor overloading in Java allows a class to have multiple constructors with different parameter lists. The compiler distinguishes them based on the number and type of arguments passed during object creation.
class Box {
double width, height, depth;
Box() {
width = height = depth = 0;
}
Box(double len) {
width = height = depth = len;
}
Box(double w, double h, double d) {
width = w;
height = h;
depth = d;
}
}
public class Main {
public static void main(String[] args) {
Box b1 = new Box();
Box b2 = new Box(10);
Box b3 = new Box(10, 20, 30);
}
}Differentiate between Abstract classes and interfaces.
Answer
Sign in to view the complete answer paper.
What is inheritance? What are the costs of inheritance? Explain hierarchical and multi-level inheritance.
Answer
Sign in to view the complete answer paper.
Is every nested class an inner class? Justify your answer.
Answer
Sign in to view the complete answer paper.
What is the role of CLASSPATH variable for package usage?
Answer
Sign in to view the complete answer paper.
Write a program to append a file content to another file, read the two file names as command line arguments.
Answer
Sign in to view the complete answer paper.
What is the need of string Tokenizer?
Answer
Sign in to view the complete answer paper.
What is the support provided by Java for network programming through java.net package? Give an the overview.
Answer
Sign in to view the complete answer paper.
How can a user define his/her own exception? Write a program to explain handling such exception.
Answer
Sign in to view the complete answer paper.
What is an event? List various types of events and respective sources of events in event handling.
Answer
Sign in to view the complete answer paper.