17
CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING Page 2 of 18 SECTION A OBJECTIVE QUESTIONS (50 marks) INSTRUCTION: This section consists of FORTY (40) objective questions. Answer ALL questions in the answer booklet. 1. Identify how the program developed is more secure when using object oriented programming. [CLO 1] A. The data developed are hidden. B. A program that has been developed can be easily upgraded from small programs to large systems. C. Eliminate redundant code and optimize usage of existing classes. D. Complexity of a program can be easily managed. 2. The following is part of java program to create an object for class Car. Identify the correct UML class diagram notation based on the program. [CLO1] Car Car myCar myCar Car Car1 : Car Car1 : Car Car new Car ( ) new Car ( ) new Car ( ) new Car ( ) A. B. C. D. Car myCar = new Car ( );

FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 2 of 18

SECTION A

OBJECTIVE QUESTIONS (50 marks)

INSTRUCTION:

This section consists of FORTY (40) objective questions. Answer ALL questions in the

answer booklet.

1. Identify how the program developed is more secure when using object oriented

programming. [CLO 1]

A. The data developed are hidden.

B. A program that has been developed can be easily upgraded from small

programs to large systems.

C. Eliminate redundant code and optimize usage of existing classes.

D. Complexity of a program can be easily managed.

2. The following is part of java program to create an object for class Car. Identify

the correct UML class diagram notation based on the program. [CLO1]

Car Car

myCar myCar

Car

Car1 : Car

Car1 : Car

Car

new Car ( )

new Car ( ) new Car ( )

new Car ( )

A.

B.

C.

D.

Car myCar = new Car ( );

Page 2: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 3 of 18

3. Identify problem domain.

Identify object.

Identify Object's Attributes.

Identify Object's Operations

Based on the list of procedures above, it refers to [CLO 1]

A. State a problem.

B. Design a problem.

C. Declare a problem.

D. Analyze a problem.

4. What is the suitable answer to fill in the Figure 1? [CLO 1]

Figure 1

A.

B.

C.

D.

I II II

Class Method Behavior

Class Attributes Method

Operation Method Class

Attributes Operation Behavior

5. “Process to delete all unnecessary attributes and remain the necessary attribute to

describe object.” This statement refers to basic terminology of

[CLO 1]

A. data abstraction

B. polymorphism

C. object

D. class

I

III

II

Page 3: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 4 of 18

6. State the method from the given problem statements.

“A bank account consists of a name of depositor, account number, type of

account and balance amount in the account. Depositor can deposit an amount

into their account and withdraw their amount.” [CLO 3]

A. Name of depositor, account number, type of account

B. Depositor amount, withdraw amount, bank account

C. Name of depositor, account number, bank account

D. Depositor amount, withdraw amount

7. What is the function of Java compiler? [CLO 1]

A. converts source code into byte code

B. converts source code into unicode

C. converts byte code into source code

D. converts byte code into psuedocode

8. What is the tool use to produces header files for use with native methods?

[CLO 1]

A. jar

B. java

C. javap

D. javah

9. Which one of the following are reserved word in Java? [CLO 1]

A. package, return, double, class, pi

B. return, continue, static, protected, boolean

C. public, static, private, boolean, chase

D. protected, int, void, class, trouble

10. What is the first name of Java? [CLO 1]

A. Sun

B. Bean

Page 4: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 5 of 18

C. Oak

D. Coffee

Question 11-12 are based on the following scenarios:

SportsCar, Inc. sells sports car from their catalog. Business is growing 30%

per year, and they need a new order entry system. You have been contracted

by SportsCar to design the new system.

SportsCar produces a catalog of car every six months and mails it to

subscribers. Each car in the catalog has an item identifier (ID) and price.

11. Analyze the scenario using OOAD and identify the possible objects.

I. Order

II. Car

III. Customer

IV. Mail

[CLO 3]

A. I, II

B. I, II, III

C. I, II, IV

D. I, II, III, IV

Page 5: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 6 of 18

12. Analyze the scenario using OOAD and identify the possible data member and

member function for Car. [CLO 3]

Car

ID: char

Price:double

calculatePrice(): double

display()

Car

ID: char

calculatePrice(): float

display()

13. Which of the following is the exactly naming convention of object method?

[CLO 1]

A. method Compute_AREA

B. method ComputeArea

C. method computeArea

D. method Computearea

14. Which of the following is the type of errors? [CLO 1]

A. Compile error, runtime error and read error

B. Compile-time error, class error and logic error

C. Compute error, runtime error and logic error

D. Compile-time error, runtime error and logic error

Car

ID: char

Price:double

Color:char

calculatePrice(): float

display()

Car

ID: char

Price:double

Color:char

calculatePrice(): double

display()

C.

D.

A.

B.

Page 6: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 7 of 18

Question 15-16 are based on the following source code:

15. Define the correct meaning of statement in line 3, “int x”. [CLO 1]

A. Declare x to be a float variable

B. Declare x to be a double variable

C. Declare x to be an integer variable

D. Declare x to be a character variable

16. Identify output from the program segment. [CLO 2]

A. The number is 20

B. The number is 21

C. The number is : 20

D. The number is : 21

1. public class number{

2. public static void main(String [] args){

3. int x;

4. x = 20;

5. System.out.println(“The number is : ”+ x);

6. }

7. }

Page 7: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 8 of 18

Question 17-18 are based on the following java program:

17. Explain code in line 5. [CLO 2]

A. Object reference variable to invoke data member

B. Declaration of object for class and assign it to class.

C. Declaration of class with reference type. Create a new object for class

and assign it to object reference variable.

D. Object reference variable to invoke member function

18. Explain code in line 8. [CLO 2]

A. Object reference variable to invoke data member

B. Declaration of object for class and assign it to class.

C. Declaration of class with reference type. Create a new object for class

and assign it to object reference variable.

D. Object reference variable to invoke member function

1 public class YellowRec

2 {

3 public static void main (String[] args)

4 {

5 Rectangle myRec = new Rectangle();

6 System.out.println("The area rectangle for

width " +

7 myRec.width + " is " +

8 myRec.calculateArea());

9 }

10 }

11 class Rectangle

12 {

13 double width = 12.3;

14 double length = 2.6;

15 double calculateArea()

16 {

17 return width * length;

18

19 }

20 }

Page 8: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 9 of 18

19. The Java IO package that we will be using is called [CLO 1]

A. java.inout

B. java.input

C. java.file

D. java.io

20. java.io does input from an input _________ of characters and does output to

an _____________ of characters. [CLO 1]

A. stream and output stream

B. output stream and stream

C. stream and input stream

D. input stream and stream

21. “Returns the number of bytes that can be read from input stream” This

statement refers to the abstract of input output stream for method

[CLO 2]

A. +read( ): int

B. +reset ( ) : void

C. +close ( ) : void

D. +available ( ) : int

22.

All methods in BufferedInputStream/BufferedOutputStream are inherited

from __________________ class. [CLO 1]

A. InputStream/OutputStream

B. FileInputStream/FileOutputStream

C. DataInputStream/DataOutputStream

D. ObjectInputStream/ObjectOutputStream

Page 9: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 10 of 18

23. Select the valid declare and create an array from the following.

[CLO 2]

A. int arr[ ] = new char[5];

B. double car[ ] = new double[10];

C. char car[ ] = new char[5];

D. char car = new char[ ];

24. What is the output of the following code fragment:

int[] ar = {2, 4, 6, 8 };

System.out.println( ar[0] + " " + ar[1] );

[CLO 3]

A. 2, 4

B. 2, 6

C. 4, 6

D. 4, 2

25. What type of exception is thrown by parseInt() if it gets illegal data?

[CLO 1]

A. NumberError

B. RunTimeException

C. ArithmeticException

D. NumberFormatException

26. Say that methodA calls methodB, and methodB calls methodC. MethodC

might throw a NumberFormatException. Can the program be written so that

methodA handles the exception? [CLO 3]

A. No, methodC must handle the exception.

B. Yes, if the header for methodC says …throws

NumberFormatException

Page 10: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 11 of 18

C. No, the exception must be handled by methodC or its caller, methodB.

D. Yes, if the headers for methodC and methodB say …throws

NumberFormatException

27. Which statement is true? [CLO 1]

A. A try statement must have at least one corresponding catch block.

B. Multiple catch statements can catch the same class of exception more

than once.

C. An Error that might be thrown in a method must be declared as

thrown by that method, or be handled within that method.

D. Except in case of VM shutdown, if a try block starts to execute, a

corresponding finally block will always start to execute.

28. What will be the output of the program? [CLO 3]

A. AC

B. BC

C. ACD

D. ABCD

public class X

{

public static void main(String [] args)

{

try

{

badMethod();

System.out.print("A");

}

catch (Exception ex)

{

System.out.print("B");

}

finally

{

System.out.print("C");

}

System.out.print("D");

}

public static void badMethod() {}

}

Page 11: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 12 of 18

29. Consider the following piece of code:

Give the values of the expressions E1.equals (E2) and E1 == E2.

[CLO 3]

A. The value of E1.equals (E2) is false, whereas the value of E1 == E2 is

true.

B. The value of E1.equals (E2) is true, whereas the value of E1 == E2 is

false.

C. The value of E1.equals(E2) is true, whereas the value of E1 == E2 is

true

D. The value of E1.equals (E2) is false, whereas the value of E1 == E2 is

false.

30. Which statement, if placed in a class other than MyOuter or MyInner,

instantiates an instance of the nested class?

[CLO 2]

A. MyOuter.MyInner m = new MyOuter.MyInner();

B. MyOuter.MyInner mi = new MyInner();

C. MyOuter m=new MyOuter

D. MyInner mi = new MyOuter.MyInner();

Employee E1 = new Employee("Karim", 5001);

Employee E2 = new Employee(E1);

public class MyOuter

{

public static class MyInner

{ public static void foo() { }

}

}

Page 12: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 13 of 18

31. Which code declares class A to belong to the mypackage.financial package?

[CLO 2]

A. package mypackage;

package financial;

B. import mypackage.*;

C. package mypackage.financial.A;

D. package mypackage.financial;

32. One of the important Java package is java.lang package. Which of the

following statement describe java.lang package? [CLO 1]

A. The java.lang package is automatically exported.

B. It contains classes and interfaces that are fundamental to virtually all

java programming.

C. It contains many mathematical methods.

D. Inherits the variables and class of object.

33. Package “java.lang.math” indicates that [CLO 1]

A. Math is a class in the package java.

B. Lang is a class in the package java.

C. Math is a class in the package lang and that lang is a package in the

package java.

D. Lang is a class in the package math and that math is a package in the

package java.

34. Identify the correct statement to put a class to “com.prenhall.mypackage”

package. [CLO 2]

A. package com.prenhall.mypackage;

B. package com.prenhall.mypackage

C. com.prenhall.mypackage Package

D. com.prenhall.mypackage Package;

Page 13: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 14 of 18

Question 35-36 based on the following program segment:

35. Define the correct explanation for statement in (i). [CLO 2]

A. Method p( ) in class A overrides the method in B.

B. Method p( ) in class A overloads the method in B.

C. Method p( ) in class B overrides the method in A.

D. Method p( ) in class B overloads the method in A.

36. Identify the output for program segment. [CLO 3]

A. The Number 10

B. The Number : 10

C. The Number 100

D. The Number : 100

37. If you do not implement all the method of an interface while implementing,

what specifier should you use for the class? [CLO 3]

A. Abstract

B. Inheritance

C. Encapsulation

D. Constructor

public class Exam{

public static void main(String[] args){

A a = new A();

a.p(10);

}

}

class B {

public void p(int i) { }

}

class A extends B{

public void p(int i) {

System.out.println(“The Number : ” +i );

}

}

(i)

Page 14: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 15 of 18

38. When a class implements an interface, what must it do? [CLO 1]

A. It must redefine each constant from the interface.

B. It must include a private method for each method in the interface.

C. It must declare a variable for each constant in the interface.

D. It must declare and provide a method body for each method in the

interface.

39. Which of the following is a correct statement to declare and initialize a string

in the segment program? [CLO 2]

A. StringBuffer strBuffer2 = new StringBuffer("Aliah");

B. StringBuffer strBuffer1 = new StringBuffer("Aliah");

C. StringBuffer Buffer1 = new StringBuffer("Aliah");

D. StringBuffer strBuffer1 = StringBuffer("Aliah");

40. What is the output of the following program segment? [CLO 2]

A. 12

B. 11

C. 10

D. 13

public class StringBufferExample{

public static void main(String[] args) {

______________________________

System.out.println("strBuffer1 : " +strBuffer1);

}

}

public class Main1 {

public static void main(String[] args) {

String str = new String("10");

int i = Integer.parseInt(str);

System.out.println(i);

}

}

Page 15: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 16 of 18

SECTION B

STRUCTURED QUESTIONS (50 marks)

INSTRUCTION:

This section consists of TWO (2) structured questions. Answer ALL questions.

QUESTION 1

a) Define polymorphism and inheritance.

[CLO 1]

(4 marks)

b) Explain TWO (2) anatomy of Java program.

[CLO 1]

(4 marks)

c) c) Answer the question below by using the given situation.

With the abstraction process you have to identify the object, attributes and

methods in the situation above. Please fill in the object, attributes and methods

you have identified in format as below. [CLO 2]

i) Object name

ii) Attribute

iii) Methods

(1 marks)

(5 marks)

(3 marks)

Klinik Fatihah Dungun is one of the new clinics

launch on January 2011. Once the patient registered, their

information will be recorded such as ic number, name of

patient, address, date, and disease. The treatment will be

done by the doctor in charge on the current day. The

appropriate medicine will be given to the patient depend

on the disease and the staff will print the patient detail for

documenting.

Page 16: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 17 of 18

d) Based on the abstraction process that student have done in (c)

question, write the encapsulation process by using the class

diagram.

[CLO 2]

(5 marks)

e) e) Describe the differences between exception handling and

assertions.

[CLO 1]

(3 marks)

QUESTION 2

(a) i) Identify the importance of Object-Oriented Analysis

(OOAD) pattern.

ii) List THREE (3) types of diagrams in UML.

[CLO 1]

(3 marks)

[CLO 1]

(3 marks)

(b) In Java, modifier is used to control access data, method and

class. State the function of each modifier for method below.

i) abstract

ii) final

iii) static

[CLO 1]

(6 marks)

(c) Answer the question based on the program segment below.

public class Mother{

public String name;

public int age;

Mother(){

name="Aminah";

age=45;

}

public void display(){

System.out.println("Name: "+name);

System.out.println("Age: "+age);

}

}

Page 17: FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING

CONFIDENTIAL FP301 OBJECT ORIENTED PROGRAMMING

Page 18 of 18

i) Create a class named Child that inherits the Mother class.

Declare an instance name location (String) for class Child.

ii) Define a constructor in class Child and give an appropriate

initial values for the instances (name, age and location).

iii) Define a method display() in class Child, execute the

display() method in superclass using the keyword super.

Method display() in class child should print the information

of name, age and location.

[CLO 2]

(2 marks)

[CLO 2]

(3 marks)

[CLO 2]

(3 marks)

iv) Create other class named Main for the main method and

create 2 objects for the 2 classes (Mother and Child). Then

execute the display() method for Mother and Child.

Example of the output:

[CLO 3]

(5 marks)

Mother's info:

Name: Aminah

Age: 45

Child's info:

Name: Sarah

Age: 20

Location: Dungun