0% found this document useful (0 votes)
4 views2 pages

Java Lab Journal: Class and Method Exercises

The document contains a series of Java programming lab questions focused on object-oriented programming concepts. It includes tasks for creating classes with constructors, implementing inheritance and interfaces, and developing a simple banking system. Each question requires the implementation of specific functionalities and methods related to the defined classes.

Uploaded by

shiniii
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)
4 views2 pages

Java Lab Journal: Class and Method Exercises

The document contains a series of Java programming lab questions focused on object-oriented programming concepts. It includes tasks for creating classes with constructors, implementing inheritance and interfaces, and developing a simple banking system. Each question requires the implementation of specific functionalities and methods related to the defined classes.

Uploaded by

shiniii
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

JAVA LAB JOURNAL QUESTIONS

Q1. Write a Java program to create a class called Student with instance variables
studentId, studentName, and grade. Implement a default constructor and a
parameterized constructor that takes all three instance variables. Use constructor
chaining to initialize the variables. Print the values of the variables.

Q2. Write a Java program to create a class called Car with instance variables make,
model, and year. Implement a parameterized constructor that initializes these
variables and assigns default values if not provided. Print the values of the variables.

Q3. Write a Java program to create a class called "Book" with instance variables title,
author, and price. Implement a default constructor and two parameterized
constructors:

• One constructor takes title and author as parameters.

• The other constructor takes title, author, and price as parameters.

• Print the values of the variables for each constructor.

Q4. Write a Java program to create a class called Classroom with instance variables
cl_name and students (an array of strings). Implement a parameterized constructor
that initializes these variables. Print the values of the variables.

Q5. Write a Java program to create a class called Constants with a static final variable
'PI' initialized to 3.14159. Create a method to calculate the area of a circle given its
radius, using the 'PI' constant. Demonstrate the method in the main method.

Q6. Write a Java program to create a class known as "BankAccount" with methods
called deposit() and withdraw(). Create a subclass called SavingsAccount that
overrides the withdraw() method to prevent withdrawals if the account balance falls
below one hundred.

Q7. Write a Java program to create a class called Employee with methods called work()
and getSalary(). Create a subclass called HRManager that overrides the work() method
and adds a new method called addEmployee().
Q8. Write a Java program to create a class known as Person with methods called
getFirstName() and getLastName(). Create a subclass called Employee that adds a new
method named getEmployeeId() and overrides the getLastName() method to include the
employee's job title.
Q9. Write a Java program to create an interface Sortable with a method sort that sorts
an array of integers in descending order. Create two classes Ascending and
Descending that implement the Sortable interface and provide their own
implementations of the sort method.
Q10. Write a Java programming to create a banking system with classes- Bank,
SavingsAccount, and CurrentAccount. Create an interface called Accounts with
methods to deposit, withdraw and view balances. The Bank class should have a list of
accounts and methods for adding them. SavingsAccount and CurrentAccount should
implement the Account interface and have their own unique methods.

You might also like