Attachment 1 26
Attachment 1 26
Weighting: 25%
Instructions:
1 HSYD201-1-Jan-Jun2025-FA1-OD-V2-08012025
The assessment covers the following learning outcomes:
Question 1 [ 23 marks]
1.2 Describe how a subclass is derived from a base class. Provide a basic example to illustrate your
answer. (5 marks)
1.3 Explain how constructors are called during inheritance. Why is it important to call the
constructor of a superclass in a subclass? (4 marks)
1.4 Explain how methods from both base and derived classes are used with a derived class
object. Provide a code snippet to illustrate. (10 marks)
2 HSYD201-1-Jan-Jun2025-FA1-OD-V2-08012025
Question 2 [56 marks]
2.1 What is information hiding in object-oriented programming? Why is it important in the context
of inheritance? (4 marks)
2.2 Describe exceptions and explain the use of “try and catch” blocks in handling exceptions in
Java. Provide a scenario where exception handling is necessary. (4 marks)
2.3.1 Define a superclass Vehicle with the attributes make, model, and a method displayDetails().
(14 marks)
2.3.2 Define a subclass Car that extends Vehicle, adds a new attribute numberOfDoors, and
overrides the displayDetails() method to include the new attribute. (14 marks)
2.3.3 In the main method, create an object of the subclass and demonstrate how to call both the
base class and derived class methods. (8 marks)
2.4 Write a Java method that accepts two integers as parameters and returns the result of dividing
them. Implement exception handling to catch and handle division by zero. (12 marks)
A small educational institution wants to implement a simple Java-based system to manage student
records. The system should be able to handle two main functionalities:
As the developer, you are tasked with building this system. Use the scenario below to answer the
following questions.
3.1 The system needs to create and manage student records using a text file. Explain the role of
the Path and Files classes in Java for file handling. Compare the use of random-access files and
sequential files, outlining when it would be more efficient to use each. (7 marks)
3 HSYD201-1-Jan-Jun2025-FA1-OD-V2-08012025
3.2 Write a Java program that creates a file named studentRecords.txt and writes the header
"Student ID, Student Name" followed by sample student records using a buffered stream. Then,
extend the program to read and display the contents of this file on the console. (7 marks)
3.3 To make the system more efficient for updating and retrieving student records, you decide to
implement random-access file handling. Write a Java program that creates a random-access file,
writes a student record (Student ID and Name) to it, and then retrieves and displays the record from
the file. (7 marks)
4 HSYD201-1-Jan-Jun2025-FA1-OD-V2-08012025