[Go to site: main page, start]

0% found this document useful (0 votes)
26 views3 pages

Java Object-Oriented Programming Guide

The document outlines a theory section for a course on Object-Oriented Programming using Java, consisting of multiple questions worth a total of 50 marks. It covers key concepts such as OOP features, variable types, constructors, inheritance, method overriding, and data types, along with practical programming exercises. Additionally, it includes tasks to create Java programs demonstrating concepts like constructor overloading, single inheritance, and complex number operations.

Uploaded by

rbanerjee162
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Java Object-Oriented Programming Guide

The document outlines a theory section for a course on Object-Oriented Programming using Java, consisting of multiple questions worth a total of 50 marks. It covers key concepts such as OOP features, variable types, constructors, inheritance, method overriding, and data types, along with practical programming exercises. Additionally, it includes tasks to create Java programs demonstrating concepts like constructor overloading, single inheritance, and complex number operations.

Uploaded by

rbanerjee162
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

OBJECT ORIENTED PROGRAMMING USING JAVA – THEORY SECTION

Total Marks: 50

Q1. [10 Marks]

a) Define Object-Oriented Programming. Explain the four main features of OOP: Encapsulation,
Inheritance, Polymorphism, and Abstraction. (5 Marks)
b) Differentiate between Procedural Programming and Object-Oriented Programming. (2 Marks)
c) What is Bytecode? Explain the role of Java Virtual Machine (JVM) in making Java platform-
independent. (3 Marks)

Q2. [10 Marks]

a) Explain the different types of variables in Java: Local, Instance, and Static with suitable examples.
(4 Marks)
b) List and explain all Java Access Specifiers (public, protected, private, and default). (3 Marks)
c) What are primitive and non-primitive data types? Give examples of each. (3 Marks)

Q3. [10 Marks]

a) Define a constructor. Explain the difference between default, no-argument, and parameterized
constructors with examples. (5 Marks)
b) What is constructor overloading? How does it differ from method overloading? (3 Marks)
c) What is the role of the finalize() method in garbage collection? Why is its execution not
guaranteed? (2 Marks)

Q4. [10 Marks]

a) What is inheritance? Explain its types (Single, Multilevel, Hierarchical, Multiple via Interface) with
diagrams or examples. (4 Marks)
b) What is method overriding? Explain with a program showing runtime polymorphism using
dynamic method dispatch. (3 Marks)
c) What is the static keyword? Explain its use with both variables and methods. (3 Marks)

Q5.

a) How do you declare and initialize an array in Java? Write a short program to find the maximum of
array elements. (4 Marks)
b) Differentiate between String, StringBuffer, and StringBuilder classes. (3 Marks)
c) What are nested and inner classes? Write a simple example demonstrating an inner class inside an
outer class. (3 Marks)
(10 Marks) —

Write a Java program to create a class Marks with data members subject1, subject2, and subject3.

• Use constructor overloading to initialize marks:

o Default constructor (assign default marks)

o Parameterized constructor (take marks from user)

• Create a method calculateAverage() to compute and return the average marks.

• Display the marks and average for both objects.

Expected Output Example:

Default Marks: 60, 70, 80


Average: 70.0
Parameterized Marks: 85, 90, 95
Average: 90.0

(10 Marks) —

Write a Java program to demonstrate single inheritance and method overriding.

• Create a superclass Employee with data members name and salary and a method
displayInfo().

• Derive a subclass Manager that adds a data member bonus and overrides displayInfo() to
show total salary (salary + bonus).

• In main(), create an object of Manager and call displayInfo().

• Expected Output Example:

Name: Rahul
Base Salary: 50000
Bonus: 10000
Total Salary: 60000

(10 Marks)

Write a Java program to create a class Complex to represent complex numbers.

• Include data members: real and imag.

• Include methods:

o input() → to take input of complex number

o add(Complex c) → to add two complex numbers (accept another object as


parameter)

o display() → to display the result in proper form (e.g., 3 + 4i)


• Use a method that returns an object containing the sum of two complex numbers.

Expected Output Example:

Enter first complex number: 2 + 3i


Enter second complex number: 4 + 5i
Sum = 6 + 8i

You might also like