Oodj Test1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

OODJ Test Page 1 of 4

Answer all questions (25 marks)

Questions 1 (1 mark)

What is the result when this code is executed?

a) 3
b) 321
c) 123
d) The code runs with no output

Questions 2 (1 mark)

Which Man class properly represents the relationship “Man has a best friend who is a
Cat”?

a) class Man extends Cat{}


b) class Man implements Cat{}
c) class Man { private BestFriend cat; }
d) class Man { private Cat bestFriend; }

Level 2 Asia Pacific University of Technology & Innovation


OODJ Test Page 2 of 4

Questions 3 (1 mark)

The image represents a complete package structure for a set of classes: “com” is the
beginning of the fully qualified package name for all classes.

Given this package structure, insert the code needed to make the car class compile and
run successfully. All the three placeholders must be filled. If fewer than three
statements are needed, use the “//blank” option.

a) package com.foo.bar.blatz;
package com.bar.*;
import com.foo.bar.Book;
b) package com.bar.*;
import com.foo.bar.*;
import com.foo.bar.blatz.*;
c) import com.foo.bar.blatz.*;
package com;
//blank
d) import com.bar.*;
import com.foo.*;
package com.foo.bar.blatz;

Level 2 Asia Pacific University of Technology & Innovation


OODJ Test Page 3 of 4

Questions 4 (1 mark)

What is the result when this code is executed?

a) TestA
b) TestB
c) TestA
TestB
d) TestB
TestA

Questions 5 (1 mark)

Which one statement is true?


a) Has-a relationship should never be encapsulated.
b) Has-a relationship should be implemented using inheritance.
c) Has-a relationship can be implemented using instance variables.
d) The relationship between Movie and Actress is an example of an is-a
relationship.

Level 2 Asia Pacific University of Technology & Innovation


OODJ Test Page 4 of 4

Questions 6 (10 marks)

Given the following diagram:

 Account class is having 2 attributes: int id and double balance


 Customer class is having 2 attributes: String name and Account myAccount

a) Transform the given diagram to Customer and Account Java classes with
appropriate constructors.
b) Illustrate how to create a Customer object with name “Joseph” is having an
Account with id of 12345 and balance of 500.0 by completing the following
Testing program.

public class Testing{


public static void main(String[] args){
Customer c;
//complete the program
}
}

Questions 7 (10 marks)

Convert the following programs by implementing the concepts of encapsulation and


modularity.

public class Account{


public double balance;
public Account(double x){
balance = x;
}
}
public class TestAccount{
public static void main(String[] args){
Account x = new Account(500.00);
//modify the account balance
x.balance = 550.00;
//withdraw 100.00 from the account
x.balance = x.balance – 100.00;
//deposit 250.00 to the account
x.balance = x.balance + 250.00;
//access the account balance
System.out.println(x.balance);
}
}

Level 2 Asia Pacific University of Technology & Innovation

You might also like