Question 1
a) Explain an example from using the Java Swing Toolkit where dynamic binding arises.
b) Specify three conditions required to be followed in writing code, for polymorphic method
calling to occur at runtime.
[1 + 3 = 4 marks]

Question 2
Assume there are two classes. One is a subclass of the other class. Both the superclass and the
subclass have just one constructor each, and in both cases, the constructor expects to receive
a) Can we use ‘new’ with the superclass, and provide no parameters, to make an object of
that superclass type, for example: Superclass sup = new Superclass();
b) When we write the subclass constructor, is there any thing we must remember to include in
the code, because of the design of the superclass? If yes, what is it that we must include?
[1 + 1 = 2 marks]

Question 3
a) List at least 3 consequences of marking a class as abstract in a .java file regarding the use
of that class and the methods provided in that class?
b) Can an abstract class say that it implements an interface? If so, must that class provide
bodies for the methods of the interface it purports to implement? Or if not, why not?
[2 + 1 = 3 marks]

Question 4
A program is being written by the Australian government to keep track of the details of businesses
that operate within Australia. Each business is given a unique 11 digit identifying code, called an
ABN (Australian Business Number). However, 2 digits of these 11 digits are check-digits,
calculated by processing the other 9 digits through an algorithm, so not every single 11 digit-long
number is a valid number to use; and not every valid 11 digit-long number is going to be in use all
the time because there are only a few million businesses actually operating in Australia. The
details are represented by objects of the BusinessData class type.

a) Which abstract data type (from the Java Collections API, java.util) would be the most
appropriate one to use to store objects that describe the key details about businesses, so
that we can quickly and easily access the details of a business by knowing its ABN code?

b) If the collection object will be named allBusinesses, how will you declare and instantiate
this object to use a class of the kind mentioned in your answer to part (a)? (Note, an 11
digit number requires you to use a long, rather than an int.)

c) Assuming the details of a business are in a newly instantiated object named
myNewBusiness, and the ABN code is 51818692256, how would you store the object into
the collection object created in your answer to part (b)?

d) At a later date if you want to retrieve the object that was stored in the collection, using the
same ABN code, what statement would you write to retrieve it and place its reference into a
variable named retrievedBusiness?


本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail:  微信:itcsdx