You are on page 1of 6

OOP TEST 2

2 hrs Instructions: Answer all questions within this document. Practical Question#1 Write a class encapsulating the concept of a home, assuming that it has the following attributes: the number of rooms, the square footage, and whether it has a basement(boolean). [5mrks]

Question2 ou ma! use some of the information from "uestion#$ to answer this question. % de&eloper wants a program written to capture information regarding homes to be de&eloped. 'he program should allow a user to $. enter and store information regarding each house [(mrks] (. pro&ide report on a list of the details of all houses without basement [(mrks] ). pro&ide list with details of all houses [(mrks] ou should also pro&ide the e*it option. +ncorporate the use of e*ception handling where necessar!. +ncorporate the use of files to make the data persistent. %ppropriate use of control structure,ob,ect creation, method calls, etc. [$mrk] [( mrks] [) mrks] [)mrks]

Theory
.1 Inheritance is the process by which a new class known as a _________ - is created from another class, called the _____________.

.a .b .c .d .2

base class, derived class derived class, base class inherited class, base class base class, inherited class

A derived class is also called a .a sub class .b super class .c base class .d all of the above If the .a .b .c .d final modifier is added to the definition of a method, this means! "he method may be redefined in the derived class. "he method may be redefined in the sub class. "he method may not be redefined in the derived class. #one of the above.

.$

"he special synta% for invokin& a constructor of the base class is! .a super'( .b base'( .c parent'(

.d .)

child'(

A method or instance variable modified by protected! **** .a can not be accessed by name inside its own class definitions. .b can not be accessed by name inside any class derived from it. .c can not be accessed by name in the definition of any class in the same packa&e. .d can not be accessed by name in any other class 'that is, other than classes named in a-c.(. __________ refers to the ability to associate many meanin&s to one method name by means of the late bindin& mechanism. .a Inheritance .b ,ncapsulation .c -olymorphism .d #one of the above A class that has at least one abstract method is called an! .a concrete class .b encapsulated class .c abstract class .d private class A class with no abstract methods is called a

.+

..

./

.a .b .c .d .0

concrete class encapsulated class abstract class private class

"he ,%ception class belon&s to the packa&e! .a 1ava.io .b 1ava.util .c 1ava.lan& .d 1ava.e%cept

.12 "he catch block has ________ parameters. .a 3ero .b one .c two .d three .11 If a method throws an e%ception, and the e%ception is not cau&ht inside the method, then the method invocation! .a terminates .b transfers control to the catch block .c transfers control to the e%ception handler .d none of the above .12 A runtime e%ception is a4an! .a checked e%ception .b unchecked e%ception .c offendin& e%ception .d none of the above .1 A _________ block e%ecutes re&ardless of whether an e%ception occurs. .a final .b finally .c catch .d none of the above

.1$ In 5ava, when you open a te%t file you should account for a possible! .a 6ile#ot6ound,%ception .b 6ile6ull,%ception .c 6ile#ot7eady,%ception .d all of the above .1) A class that uses an interface must use the keyword! .a ,%tends .b Inherits .c 8uper .d Implements .1+ In 5ava, a derived class can have ________ base class'es(. .a one .b two .c three .d there is no limit .1. 9hich method is used to place an entire Array:ist into a file

.a .b .c .d

write write;b1ect read6ile read;b1ect

.1/ Laptop extends Computer. 9hich of the followin& is true based on the previous statement* .a :aptop is the superclass of <omputer .b <omputer inherits features from :aptop .c :aptop is the derived class while computer is the based class .d <omputer is the subclass of :aptop .10 A #umber6ormat,%ception is an e%ample of a .a <hecked e%ception .b =nchecked ,%ception .c I;,%ception .d #one of the above .22 ;utline the error within the statement below and &ive a recommended solution!

Laptop extends Computer, MobileDevice


5ava can only e%tend one class> therefore, computer should be the based class from which laptop and mobile devices are derived. "he use of the term mobile device to desribe laptop is rapidly diminishin& so in conte%t it would make sense havin& ?obile@evice and :aptop as a subclasses of <umputer .

You might also like