0% found this document useful (0 votes)
16 views9 pages

Oops Program List

The document outlines the practical examination program for Object Oriented Programming (OOPS) using Java at RVS College of Arts and Science. It includes a list of tasks covering various topics such as class creation, constructors, data structures, inheritance, exception handling, and debugging programs. Each task specifies the requirements for creating Java classes and methods, along with examples and expected outcomes.

Uploaded by

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

Oops Program List

The document outlines the practical examination program for Object Oriented Programming (OOPS) using Java at RVS College of Arts and Science. It includes a list of tasks covering various topics such as class creation, constructors, data structures, inheritance, exception handling, and debugging programs. Each task specifies the requirements for creating Java classes and methods, along with examples and expected outcomes.

Uploaded by

anandhi.k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

RVS COLLEGE OF ARTS AND SCIENCE, (AUTONOMOUS)

SCHOOL OF COMPUTER STUDIES (UG)


MARCH 2024 EOS PRACTICAL EXAMINATION
PROGRAM LIST

Subject Code: 23P


Subject: Object Oriented Programming(OOPS) using java
Date of Exam:
Session: FN / AN

1) Creating and Using a Simple Class


Task 1: Creating the Person Class
● Create a Java class named Person.
● Add instance variables for firstName (String), lastName (String), and age (int).
● Create a default constructor to initialize these variables.
● Implement a parameterized constructor to set the values for firstName,lastName, and
age.
● Implement a method called getFullName that returns the full name(concatenation of
firstName and lastName).
Task 2: Using the Person Class
● In the main method, create two Person objects with the following data:
○ Person 1: First Name = "John", Last Name = "Doe", Age = 30
○ Person 2: First Name = "Alice", Last Name = "Smith", Age = 25
● Display the full names and ages of both persons using the getFullName method.
● Calculate and display the average age of the two persons.
Task 3: Additional Operations
● Implement a method in the Person class to check if a person is a teenager (agebetween
13 and 19).
● Create a new Person object with age 18 and use the method to check if they are a
teen ager.
● Modify the Person class to include a toString method that returns a formattedstring
representation of a person's information.
● Display the formatted information of all created persons using the toStringmethod.
2) Constructors and the this Keyword
Task 1: Creating the Product Class
● Create a Java class named Product to represent a product with attributes:
productId (int), productName (String), and price (double).
● Implement a parameterized constructor that initializes these attributes.
● Use the this keyword to distinguish between instance variables and constructor
parameters.
● Implement a method called displayProductInfo to display the productinformation (ID,
name, and price).

1
Task 2: Using the Product Class
● In the main method, create three instances of the Product class with thefollowing data:
○ Product 1: ID = 101, Name = "Laptop", Price = 999.99
○ Product 2: ID = 202, Name = "Smartphone", Price = 499.95
○ Product 3: ID = 303, Name = "Tablet", Price = 299.50
● Display the information of all three products using the displayProductInfomethod.
Task 3: Additional Operations
● Implement a method in the Product class to calculate and return the discountedprice of
a product. Allow specifying a discount percentage.
● Create a new Product object and calculate and display the discounted price witha 10%
discount.
● Modify the Product class to include a static variable for tracking the total numberof
products created. Implement a static method to retrieve this count.
● Display the total number of products created in the main method.

3) Implementing a Stack Data Structure

Task 1: Creating the Stack Class


● Create a Java class named Stack to implement a stack data structure.
● Use an array to store the stack elements.
● Include methods push (to add elements), pop (to remove elements), and isEmpty
(to check if the stack is empty).
● Set a maximum capacity for the stack (e.g., 10 elements) and handle overflow
conditions.
Task 2: Using the Stack Class
● In the main method, create an instance of the Stack class.
● Push a series of integers onto the stack (e.g., 5, 10, 15, 20).
● Display the contents of the stack after each push operation.
● Pop elements from the stack and display them until the stack is empty.
● Test the isEmpty method to confirm if the stack is empty.
Task 3: Additional Operations
● Implement a method in the Stack class to display the top element of the stack
without removing it (peek).
● Use the peek method to display the top element before and after popping
elements from the stack.
● Add error handling to the pop method to handle underflow conditions when the
stack is empty.

2
4) Overloading Constructors and Returning Object
Task 1: Creating the Product Class
● Create a Java class named "Product."
● Add instance variables for productId (int), productName (String), and price(double).
● Implement multiple constructors for initializing these variables.
Task 2: Using the Product Class
● In the main method, create two Product objects using different constructors.
● Display the details (id, name, price) of both products.
Task 3: Additional Operations
● Implement a method in the Product class that calculates the total cost by
multiplying the price with a given quantity.
● Create a new Product object and calculate the total cost for a quantity of 5 units.
● Display the total cost of the product.
5) Introducing Nested and Inner Classes
Task 1: Creating the University Class
● Develop a Java class named "University" with an inner class "Department."
● The University class should have attributes such as universityName (String) and
yearFounded (int).
● The Department inner class should include attributes like departmentName(String) and
numberStudents (int).
Task 2: Using Nested and Inner Classes
● Instantiate the University class and create instances of multiple Departmentinner
classes within it.
● Display the details of the university and each department created.
Task 3: Additional Operations
● Implement a method in the University class to calculate the total number ofstudents
across all departments.
● Use this method to display the overall student count in the university.
6) Exploring the String Class and Command-Line Arguments
Task 1: String Manipulation
● Develop a Java program to manipulate strings using various methods from theString
class.
● Include operations such as concatenation, substring extraction, and character
replacement.
Task 2: Command-Line Argument Processing
● Create a program that takes command-line arguments representingmathematical
operations (e.g., add, subtract, multiply) and correspondingoperands.
● Perform the specified operation on the provided operands and display the result.
Task 3: Additional Operations
● Extend the command-line argument program to handle different data types for
operands (integers, doubles).
● Ensure robust error handling for incorrect inputs and display appropriate error
messages.

3
7) Inheritance Basics and Method Overriding
Task 1: Member Access and Inheritance
● Create a superclass "Vehicle" with attributes like make (String), model (String),and
Year(int).
● Develop a subclass "Car" inheriting from "Vehicle" with an additional attribute,color
(String).
● Implement methods in both classes for displaying details.
Task 2: Using super and Method Overriding
● Use "super" to call the superclass constructor from the subclass "Car".
● Override the display method in "Car" to include color information.
Task 3: Dynamic Method Dispatch and Object Class
● Demonstrate dynamic method dispatch by storing "Car" objects in an array of
"Vehicle".
● Utilize the overridden method to display details, showcasing runtimepolymorphism.

8) Creating Multilevel Hierarchy and Using Abstract Classes

Task 1: Multilevel Inheritance


● Design a base class "Animal" with basic attributes and methods.
● Create subclasses "Mammal" and "Bird" inheriting from "Animal" and adding
specific attributes.
● Implement a subclass "Parrot" extending from "Bird" with additional
characteristics.
Task 2: Abstract Classes and Final with Inheritance
● Introduce an abstract method in the "Animal" class for sound.
● Prevent further inheritance by using "final" with certain methods or classes.
Task 3: Object Class and Method Overriding
● Discuss and demonstrate the use of methods from the "Object" class such as
toString() and equals().
● Override the toString() method in the subclasses for specific representations.
9) Using Super and Final in Inheritance
Task 1: Using super and Constructor Execution
● Create a superclass "Person" with basic details and a constructor.
● Derive a subclass "Employee" from "Person" with additional attributes and
Utilize"super" in its constructor.
Task 2: Final to Prevent Overriding and Inheritance
● Make specific methods in the "Person" class as final to prevent method
overriding.
● Utilize final on the "Person" class to prevent further subclassing.
Task 3: Applying Method Overriding and Object Class
● Override a method in the "Employee" class and display its unique information.
● Discuss and demonstrate the use of "Object" class methods in the context of the
superclass and subclass.

4
10) Packages and Access Protection
Task 1: Defining a Package
● Create a package named "utilities".
● Define a class "Calculator" within the "utilities" package with basic
Arithmetic operations (addition, subtraction, multiplication, division).
Task 2: Access Protection and Importing Packages
● Develop another package named "app" outside the "utilities" package.
● Create a class "MainApp" in the "app" package to utilize the Calculator class fromthe
"utilities" package.
● Use different access modifiers (public, private, default) within this setup Andexplore
their effects.
Task 3: CLASSPATH and Packages
● Discuss and demonstrate the concept of the CLASSPATH in relation to packages.
● Execute the MainApp class, highlighting how the CLASSPATH helps in Locating the
classes from different packages.
11) Interfaces and Default Interface Methods
Task 1: Defining and Implementing Interfaces
● Create an interface "Shape" defining methods for calculating area and perimeter.
● Implement the "Shape" interface in classes like "Rectangle" and "Circle"
Providing area and perimeter calculations for each shape.
Task 2: Applying Interfaces and Default Methods
● Introduce another interface "Resizable" with a default method for resizingshapes.
● Implement this interface in the "Rectangle" class and demonstrate the useof the default
method to resize a rectangle.
Task 3: Multiple Interface Implementation
● Implement the "Shape" and "Resizable" interfaces in another class "CustomShape".
● Discuss and showcase how a class can implement multiple interfaces, Utilizingmethods
from both interfaces.
12) Nested Interfaces and CLASSPATH
Task 1: Nested Interfaces and Variables in Interfaces
● Define an interface "Outer" containing a nested interface "Inner" with Methodsand
variables within both interfaces.
● Implement the "Inner" interface in a class and use the interface variables in the
implementing class.
Task 2: Using Static Methods in Interfaces
● Extend the "Outer" interface with a static method.
● Demonstrate the usage of this static method without implementing the interface,
directly accessing it through the interface name.
Task 3: Applying Nested Interfaces
● Create another class "NestedInterfaceClass" implementing the "Outer.Inner"interface.
● Discuss the syntax and implications of implementing a nested interface Outsideits
enclosing interface and utilizing its functionality.

5
13) Exception Handling Fundamentals
Task 1: Exception Types and Using try-catch
● Introduce a scenario where an ArithmeticException might occur (e.g., dividing by
zero).
● Use try-catch blocks to handle the ArithmeticException gracefully and display an
error message.
Task 2: Multiple catch Clauses and Nested try Statements
● Create a situation involving a FileNotFoundException (e.g., attemptingto access anon-
existent file).
● Implement multiple catch clauses to handle different exceptions, including
IOExceptionand FileNotFoundException.
● Utilize nested try statements to demonstrate handling exceptions within deeper
Code blocks.
Task 3: Finally and Uncaught Exceptions
● Illustrate a scenario where a NullPointerException might occur (e.g., accessing a
method of a null object).
● Utilize a finally block to execute essential cleanup or finalization code.
● Discuss uncaught exceptions and their impact on the program's flow, demonstrating
an uncaught exception.

14) Creating Custom Exception Classes


Task 1: Creating Your Own Exception Subclasses
● Design a custom exception class named "CustomException" extending the
Exceptionclass.
● Implement constructors allowing customization of error messages and chaining
to superclass constructors.
Task 2: Chained Exceptions and Exception Features
● Create a scenario where a CustomException is thrown due to an underlying cause,
such as an IllegalStateException.
● Use chained exceptions to maintain the root cause while handling
CustomExceptioninstances.
● Discuss and demonstrate the benefits of chained exceptions in tracing errors.
Task 3: Using throw and throws
● Develop a method that throws a CustomException based on specific conditions
(e.g.,invalid input).
● Implement a class to catch and handle this CustomException by using the throws
keyword in method signatures.

6
15) Java’s Built-in Exceptions and Advanced Exception Handling
Task 1: Java’s Built-in Exceptions
● Explore the IndexOutOfBoundsException by attempting to access an index beyond
the size of an array.
● Handle this exception using try-catch and display a meaningful error message.
Task 2: Recently Added Exception Features
● Demonstrate the use of try-with-resources to automatically close resources, such as
file streams or database connections.
● Utilize the improved handling of multi-catch exceptions introduced in Java 7 or later.
Task 3: Using Exceptions in Practice
● Create a scenario where an IllegalArgumentException might occur (e.g.,
Invalidargument passed to a method).
● Implement a method that validates the input and throws IllegalArgumentException
If invalid.
● Handle this exception effectively by providing guidance on correct inputs.

16) Debug the given program and find the output.


class A {
i;
int j;
void setij(int x, int y)
{
i = x;
j = y;
}
}
class B extend A {
int total;
void sum() {
total = i + j;
}
}
public class Access {
public static void main(String args[]) {
B subOb = new B();
subOb.setij(10, 12);
subOb.sum();
System.out.println("Total is " + subOb.total)
}
}

7
17) Debug the given program and find the output.
public class GFG {
static void swapValuesUsingThirdVariable(int m, int n)
{
temp = m;
m = n;
n = temp;
System.out.println("Value of m is " + m + " and Value of n is " + n)
}

public static void main(String[] args)


{
int m = 9, n = 5;
swapValuesUsingThirdVariable(m, n);
}}

18) Debug the given program and find the output.

public class MaxOfThreeNumbers {


public static void main(String[] args) {
num1 = 10, num2 = 20, num3 = 15, max;
max = (num1 > num2) ? (num1 > num3 ? num1 : num3) : (num2 > num3 ? num2 :
num3);
System.out.println("Maximum Number is " +max)
}
}

19) Debug the given program and find the output.


public class Factorial {
public static void main(String[] args) {
int num = 5, factorial = 1;
for(int i = 1; i <= num; ++i);
{
factorial *= i;
}
System.out.println("Factorial of" + num + " is: " + factorial);
}
}

8
20) Debug the given program and find the output.

public class EvenOdd {


public static void main(String[]) {
int num =;
if(num % 2 == 0)
System.out.println(num + " is even.");
else
System.out.println(num + " is odd.");
}
}

Internal Examiner External Examiner


Name: Name:
Signature: Signature:

You might also like