Name:
University number:
Object-Oriented Programming
Assignment #1
Q1: Explain the concept of returning an object from a method in Java. Illustrate your
explanation by describing what happens in the following code snippet: (2 Marks)
public Fraction1 simplify() {
int num = getNumerator();
int denom = getDenominator();
int gcd = gcd(num, denom);
Fraction1 simp = new Fraction1(num / gcd, denom /
gcd);
return simp;
}
Name:
University number:
Q2: Explain the difference between one-dimensional and two-dimensional arrays in Java.
How would you access an element in a two-dimensional array, and what are some practical
applications of such arrays? (1.5 Marks)
Name:
University number:
Q3: Explain the difference between method overriding and method overloading in Java.
How does method overriding support runtime polymorphism? Provide an example to
illustrate your answer. (1.5 Marks)
Name:
University number:
Q5: What are the different levels of access protection available for members within a class
in Java? How do packages play a role in access control? (2 Marks)
Name:
University number: