100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
CS1410 Java Program Development $18.99   Add to cart

Exam (elaborations)

CS1410 Java Program Development

 3 views  0 purchase
  • Course
  • CS1410 Java Program Development
  • Institution
  • CS1410 Java Program Development

CS1410 Java Program Development 1. (Compulsory Question) Read the following partial problem specification. The task is to develop a simulation of an air traffic control system. There are several different types of aircraft, so an abstract base class has been created. Each aircraft has an integ...

[Show more]

Preview 2 out of 11  pages

  • October 8, 2024
  • 11
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
  • CS1410 Java Program Development
  • CS1410 Java Program Development
avatar-seller
EXCELLENTSCORES1
lOMoARcPSD|47166518




AN
1. (Compulsory Question)
CS1410 Java Program Development




Read the following partial problem specification.

The task is to develop a simulation of an air traffic control system. There are several
different types of aircraft, so an abstract base class has been created. Each aircraft
has an integer code, initialised in the constructor. It is also possible to find out the
remaining flying time (or CAPACITY), measured in minutes, before the aircraft
must land.
The following block of code contains a skeleton implementation of the Aircraft
class.
Beginning of code
SW
1 public abstract class Aircraft {
2 protected int code;
3

4 public Aircraft(int code) {
5 this.code = code;
6 }
7

8 public abstract int getFlyingCapacity();
9 }
End of code


a) Aircraft is an ‘abstract class’. What are the implications of this?
(4 marks)
Model Answer:

• It is impossible to instantiate Aircraft objects.
• Any subclass of Aircraft can only be concrete if all abstract methods are defined.

(2 marks) for each point.
ER
b) Define the difference between public and protected access. Explain why it is
appropriate to make the code field protected.
(6 marks)
Model Answer:

public members can be accessed by any other class (2 marks) ; protected members can only
be accessed by the same class, its subclasses (and other classes in the same package) (2 marks) . It is
appropriate to make code protected since subclasses may need direct access to it, and it shouldn’t be
public as that would break encapsulation (2 marks) .

c) Plane is a concrete subclass of Aircraft. In the constructor for Plane, as well as
the code, a field for the flying capacity (in minutes) corresponding to the initial fuel load
should be initialised. This field value should be returned by the getFlyingCapacity
S
method. Write down a definition of this class.
(8 marks)
Model Answer:

1 OF 11

Downloaded by Austine Wanjala (wanjala883@gmail.com)

, lOMoARcPSD|47166518




AN 1
CS1410 Java Program Development



Beginning of code
public class Plane extends Aircraft {
2 private int flyingCapacity;
3

4 public Plane(int code, int flyingCapacity) {
5 super(code);
6 this.flyingCapacity = flyingCapacity;
7 }
8

9 public int getFlyingCapacity() {
10 return flyingCapacity;
11 }
12 }
End of code
SW
(2 marks) for the class declaration, (1 mark) for the field declaration, (1 mark) for the
constructor declaration, (2 marks) for the call to super, (1 mark) for initialising the field, and
(1 mark) for the body of the method getFlyingCapacity.

d) Consider the following code fragment (arguments omitted on line 1, but you may as-
sume that they are correct).
Beginning of code
1 Plane p = new Plane(....);
2 Aircraft a = p;
3 System.out.println(a.getFlyingCapacity());
End of code

i) Define the ‘static type’ of a variable. In the above code fragment, what are the static
types of p and a?
(5 marks)
Model Answer:
ER
The static type of a variable is its declared type and is determined at compile time (3 marks) . p has
static type Plane and a has static type Aircraft; (1 mark) each.

ii) Define the ‘dynamic type’ of a variable. In the above code fragment, what are the
dynamic types of p and a?
(5 marks)
Model Answer:

The dynamic type of a variable is the type of the object to which it refers; this can change during the
execution of a programme (3 marks) . p has dynamic type Plane and a has dynamic type Plane;
(1 mark) each.

iii) Define the term ‘method overriding’. Explain, with the aid of a diagram, the se-
quence of events in the JVM when the method call a.getFlyingCapacity()
occurs on line 3.
(7 marks)
S
Model Answer:


2 OF 11

Downloaded by Austine Wanjala (wanjala883@gmail.com)

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller EXCELLENTSCORES1. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $18.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

76799 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$18.99
  • (0)
  Add to cart