cmpt 270 midterm final

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/71

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

72 Terms

1
New cards

the major difference between stack memory and heap memory is that the stack is used to store the order of method execution and local variables while the heap memory stores the objects and it uses dynamic memory allocation and deallocation

true or false

true

2
New cards

in java, the default value for a class variable of type int is -1.

true or false

false

3
New cards

instance variables are used to represent an object’s state

true or false

true

4
New cards

subclasses can access private instance variables of the superclass

true or false

false

5
New cards

when writing regression tests, it is ok to directly interact with private variables

true or false

false

6
New cards

a uml use case diagram is considered a behavioural diagram, as opposed to a structural diagram

true or false

true

7
New cards

in java, the toString() method automatically collects a class’ attributes and generated a formatted string representation of the class

true or false

false

8
New cards

you need to provide the size of an arrayList when you are creatin the arrayList

true or false

false

9
New cards

polymorphism can be used with both inherit super types and implemented supertypes

true or false

true

10
New cards

which of the following is not a class found in java’s collection framework

a) arraylist

b) hashmap

c) hashset

d) dictionary

dictionary

11
New cards

which of the following are not important for a regression test program?

a) constructing objects are calling methods

b) displaing the results of the method calls

c) displaying the values that you expect to get

d) reading input from the user

reading input from the user

12
New cards

suppose the class coffee extends the class drink. which one of the following assignments is legal?

  • drink x = new drink();

  • coffee y = new coffee();

a) y = x;

b) x = y;

c) y = new drink();

d) new drink() = new coffee();

x = y;

13
New cards

suppose you are to design an inheritance hierarchy with the following classes: mouse, cat, mammal, and tiger. which of these is the superclass?

a) tiger

b) mammal

c) mouse

d) cat

mammal

14
New cards

which programming technique should be used if you want a method to have different behaviour depending on the class of the object that is invoking it?

a) polymorphism

b) the instaceof operator

c) an if-else statement

d) the getclass method

polymorphism

15
New cards

which of the following java snippets would be used to declare a hashmap that contains items of type exam and is accessed by a key of type string?

a. hashmap<exam> exams = new hashmap<string>();

b. hashmap<t> exams = new hashmap<t>();

c. map<exam, string> exams = new hashmap<exam, string>();

d. map<string, exam> exams = new hashmap<string, exam>();

d

16
New cards

when should you delete your testing code from a class?'

a) if it is a simple class you don’t need to write proper regression tests

b) when all tests are passed and you know the class wont be changing

c) your regression tests should never be deleted

d) after several months without errors it makes sense to delete your tests to make your code easier to read

your regression tests should never be deleted

17
New cards

consider the following code fragment:

Object obj = “CMPT 270”;

System.out.println(ob.length());

which of the following statements are true?

a) the code compiles are runs without issue

b) the code will not compile because the Object class does not have a method called length()

c) the code will not compile because a String object cannot be assigned to something of type object

d) the code will compile but throw an exception

the code will not compile because the Object class does not have a method called length()

18
New cards

software development is all about learning a programming language

false

19
New cards

object oriented programming

a program consisting of classes and objects organized to manage the complexity of large-scale systems

20
New cards

procedural programming

a program consisting of methods/functions calling each other

21
New cards

method

implements behaviors relevant to the purpose of the system

22
New cards

field or attribute

stores data relevant to the purpose of the system

23
New cards

container object

data structure to store entities

24
New cards

entity object

model of a real-world thing in an application

25
New cards

interface object

facilitates communication between the system and the outside world

26
New cards

control object

organizes computation or flow of the program

27
New cards

a uml class diagram is a behavioral diagram

true or false

false

28
New cards

given 3 classes: plant, tree, flower, which of the following best describes their relationship to one another

inheritance

29
New cards

suppose you have 2 classes: house, and wall, where the house is a container of wall objects. which of the following best describes this relationship?

composition

30
New cards

suppose you have 2 classes: book, and bookshelf. which of the following best describes the relationship between these 2 classes?

aggregation

31
New cards

suppose you have 2 classes: hammer and nail, which of the following best describes the relationship between these 2 classes

association

32
New cards

which principle should be used if you want a method to have different behaviour depending on the specific class the method is being invoked on

polymorphism

33
New cards

which of the following statements describes an inheritance relationship?

a textbook is a book

34
New cards

interfaces and inheritance are different name’s for the same concept

true or false

false

35
New cards

using uml class diagrams you can express relationships between two classes. which of the following cannot be expresed in a uml diagram?

polymorphism

36
New cards

encapsulation

grouping related variables and functions together to reduce complexity and increase reusability

37
New cards

polymorphism

refactor ugly if and switch / case statements

38
New cards

inheritance

eliminate redundant code

39
New cards

abstraction

hide details and shows the essentials; isolate the impact of changes

40
New cards

which of the following data types is not a primitive data type in Java

a) string

b) double

c) boolean

d) int

string

41
New cards

all data types in java are references to data allocated on the heap

true or false

false

42
New cards

if you wanted to store measurement data, which Java data type is recommended?

double

43
New cards

Just like in Python, single quotes (' ') and double quotes (" ") are both used to denote a String literal.

true or false

false

44
New cards

Which of the following for loops is correct syntax in Java?

for(int i=0; i<10; i++);
{
    System.out.println("Hello"); 
}
for(int i=0; i<10; i++)
{
    System.out.println("Hello");  
}
for(int i in Range(10))
{
    System.out.println("Hello"); 
}
for(int i=0, i<10, i++)
{
    System.out.println("Hello"); 
}

for(int i=0; i<10; i++)
{
    System.out.println("Hello");  
}

45
New cards

What would be the output from the following code snippet?

int x = 10;
int y = 4;
if(x >= 10)
{
    System.out.println(x/y);
}
else
{
    System.out.println(y/x);
}

a) 2

b) 2.5

c) 0.4

d) 0

2

46
New cards

Assume you have the following String declarations. Which of the following expressions evaluate to true? (select all that apply)

 

String s1 = "Hello";
String salutation = "Hi";
String howdy = "hELLo";
String greeting = new String("Hello");

a) s1.equals(howdy);

b) s1.equals(greeting);

c) s1 == greeting

d) s1.equalsIgnoreCase(howdy);

e) s1.compareTo(salutation);

s1.equals(greeting); s1.equalsIgnoreCase(howdy);

47
New cards

what does a toString() method do in Java?

it allows a programmer to define a String representation of their class

48
New cards

the tree class does not have an explicit ‘chopDown’ method. which of the following describe the chopDown functionality in the system

a) the Tree object's height is set to 0

b) the Tree object has a boolean variable named 'isDead', which is set to true

c) the Tree object's memory is manually deallocated using free()

d) the Tree variable is set to null

the Tree variable is set to null

49
New cards

why doesn’t the Tree class have a setter/mutator to set the height attribute?

a) it does have one, the method grow() acts as a mutator

b) it doesn't need one, because the height attribute is public so any class can change it directly

c) it does have one, the method getHeight() also sets the height attribute

d) it doesn't need one, because the height attribute should never change

it does have one, the method grow() acts as a mutator

50
New cards

which class acts as the main/client program

a) treePlanter

b) inventory

c) forest

d) tree

treePlanter

51
New cards

the lecture followed a specific development process. Which of the following steps was omitted from the lecture (for now)?

a) Implementing/coding methods

b) UML

c) JUnit Testing

d) Creating stub classes/methods

e) Documentation

JUnit Testing

52
New cards

in the development process followed in the lecture, which of the following steps was last?

a) Creating stub class/methods

b) Implementing/coding methods

c) UML

d) Unit Testing

e) Documentation

Implementing/coding methods

53
New cards

debugging

inferring the cause of undesired behavior or incorrect results

54
New cards

fault

your program exhibits behaviour that is not intended / an undesired behaviour or incorrect result

55
New cards

error

the “thing” that causes a fault / the cause of an undesired behaviour or incorrect result

56
New cards

validation

any method to increase confidence in the correctness of a software system

57
New cards

failure

inability of the system to do what is required

58
New cards

coverage

how much of the code is tested

59
New cards

manual testing

a human types some input to a program

60
New cards

automated testing

the computer runs a script performing the tests

61
New cards

which of the following statements about the relationship between errors and faults is FALSE?

a) it's possible for one error to produce multiple faults

b) if there is no error in the code, there are no faults

c) it's possible for code to have an error but produce no faults

d) it's possible for a fault to be observed, but no error to cause it

it's possible for a fault to be observed, but no error to cause it

62
New cards

when should you delete your testing code from a class?

your regression tests should never be deleted

63
New cards

For CMPT 270, where will you be writing your unit tests?

In the static main method of the class being tested

64
New cards

when writing regression tests, we should print the status of each test to the console.

true or false

false

65
New cards

using the inheritance structuer discussed in the lecture, assume you have a container of type Water Monster. Which of the following types could be stored inside the container?

a) squiiirtle

b) starfishy

c) peekatu

d) monster

e) electric monster

f) water monster

squiirtle, starfisgy, water monster

66
New cards

effective use of polymorphism is good because it increases coupling in a software system

true or false

false

67
New cards

which keyword is used to indicate inheritance in java?

extends

68
New cards

polymorphism can be used with both inherited super types and implented interface types

true

69
New cards

which of the following methods are inherited from the Object class?

a) getClass()

b) equals()

c) scanner.readInt()

d) System.out.println()

e) attack()

f) toString()

getClass(), equals(), toString()

70
New cards

the downside to polymorphism is that once you have a container of the supertype, it is impossible to convert an onject back to its original type

true or false

false

71
New cards

which of the following are a benefit of polymorphism (select all that apply)

a) it reduces coupling

b) it can reduce the amount of code you need to write

c) it makes yout code simpler and more concise

d) it can make your code more flexible / adaptable

e) all of the above

all of the above

72
New cards

which keyword is used to define that a class uses an Interface in Java?

implements