cmpt 270 final: weekly quizzes : final mc : conceptual

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

1/149

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.

150 Terms

1
New cards

what is the difference between method overloading and method overriding in Java?

one means having the same method name but different parameters, while the other means a subclass changes a method that it inherits from its superclass

2
New cards

what is the purpose of the final keyword in Java?

means that a variable’s value, a method’s behaviour, and a class’ inheritance cannot be changed

3
New cards

what is the difference between a checked exception and an unchecked exception

one must be caught with try-catch or declared in the method, but the other happens during the program and don’t have to be handled explicitly

4
New cards

what is the difference between a constructor and a method in Java?

one initializes a new object, while the other performs actions on an object

5
New cards

what does the this keyword do in a constructor or method?

refers to the current instance of the class

6
New cards

what is the purpose of the super keyword in java?

refers to the superclass and is used to call parent class methods or constructors

7
New cards

explain the difference between == and equals() in Java

one checks if two objects are the exact same thing in memory, while the other checks if their contents or values are the same

8
New cards

what is the difference between a static method and a non-static method

one belongs to the class while the other belongs to an instance of the class

9
New cards

what is a final variable, and how is it different from a regular variable?

one cannot be changed once assigned, whereas a the other one can

10
New cards

how does the try-catch block work in exception handling?

one contains code that might throw an exception, and the other handles the exception if it occurs

11
New cards

what is the purpose of throw and throws keywords in Java exceptions?

one is used to cause an exception right away, while the other tells that a method might cause an exception

12
New cards

what is the difference between String and StringBuilder in Java?

one is immutable while the other is not

13
New cards

what is polymorphism and how is it used in Java?

it lets different kinds of objects be used like they are the same type, usually by replacing methods with new versions

14
New cards

what is an abstract class in Java?

is a class you can’t make objects from, but other classes can inherit from it

15
New cards

what is the difference between an interface and an abstract class in Java?

one is a list of method names without code that any class can use, and the other can have methods with or without code and other classes can extend it

16
New cards

what is a constructor overloading in Java?

occurs when multiple constructors with different parameters are defined in a class

17
New cards

what does instanceof operator do in Java?

checks if an object is of a certain type, it verifies the object’s class when the program is being ran

18
New cards

what is the purpose of the private access modifier in Java?

restricts access to a field or method to within the same class only

19
New cards

what is the null keyword in Java?

represents the absence of a value or reference for a variable

20
New cards

what is the purpose of the continue statement in Java?

skips the current iteration of a loop and moves to the next iteration

21
New cards

what is the difference between ArrayList and LinkedList?

one stores items in a growable array and lets you quickly get any item, while the other stores items in a chain and lets you add or remove items faster

22
New cards

what does the default keyword do in an interface?

lets a method in an interface have a default code that classes can use or override

23
New cards

what is method chaining?

lets you call methods one after another on the same object in one line, because each method returns the object itself

24
New cards

what is the difference between ArrayList and HashSet?

one lets you use store methods in an ordered list, because it keeps insertion order, while the other stores unique elements in no order because it does not allow duplicates

25
New cards

what is the purpose of the static keyword?

lets you use methods or variables without creating an object, because it belongs to the class itself

26
New cards

what is the difference between a method signature and a method declaration?

method signature includes the name and parameters, because it identifies the method while the method declaration includes the return type an access modifiers, because it defines the method

27
New cards

what is the purpose of the default constructor?

creates an object without setting any values because it is automatically provided if no constructor is given

28
New cards

what is the difference between Thread.sleep() and wait()?

one pauses the thread for a certain time, while the other pauses it until another is told to continue

29
New cards

what does super() do in a constructor?

calls the parent class constructor, because it ensures the parent class is properly set up

30
New cards

what is the purpose of the final keyword in method parameters?

lets you make sure a parameter’s value cannot be changed, prevents reassignment

31
New cards

what does the this keyword do in a constructor?

refers to the current object, because it helps distinguish instance variables from parameters

32
New cards

what is a hashcode?

uniquely identifies objects because it helps quickly locate and compare objects in hash-based collections

33
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

34
New cards

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

true or false

false

35
New cards

instance variables are used to represent an object’s state

true or false

true

36
New cards

subclasses can access private instance variables of the superclass

true or false

false

37
New cards

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

true or false

false

38
New cards

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

true or false

true

39
New cards

in Java, the toString() method automatically collects a class’ attributes and generates a formatted Strinag representation of the class

true or false

false

40
New cards

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

true or false

false

41
New cards

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

true or falsea

false

42
New cards

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

arraylist

hashmap

hashset

dictionary

dictionary

43
New cards

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

constructing objects are calling methods

displaying the results of the method calls

displaying the values that you expect to get

reading input from the user

reading input from the user

44
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;

45
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

46
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?

polymorphism

the instaceof operator

an if-else statement

the getclass method

polymorphism

47
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. map<string, exam> exams = new hashmap<string, exam>();

48
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

c) your regression tests should never be deleted

49
New cards

consider the following code fragment:

Object obj = “CMPT 270”;

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

which of the following statements are true?

the code compiles are runs without issue

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

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()

50
New cards

instance variables are used to model the attributes of an object

true or false

true

51
New cards

if your code contains an error, there will always be atleast one corresponding fault

true or false

false

52
New cards

Software development is all about learning a programming language.

False

53
New cards

Object Oriented Programming

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

54
New cards

Procedural Programming

A program consisting of methods/functions calling each other

55
New cards

Method

Implements behaviours relevant to the purpose of the system

56
New cards

Field or Attribute

Stores data relevant to the purpose of the system

57
New cards

Entity Object

Model of a real-world thing in an application

58
New cards

Control object

organize computation or flow of the program

59
New cards

Interface Object

Facilitates communication between the system and the outside world

60
New cards

Container Object

Data structure to store entities

61
New cards

A UML Class Diagram is a type of behavioural diagram

False

62
New cards

What does a toString() method do in Java?

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

63
New cards

The tree class does not have a ‘chopDown’ method. What describes it’s behaviour?

a) Set height to 0

b) Mark isDead = true

c) Free memory

d) Set tree to null

The tree variable is set to null

64
New cards

Why doesn’t the Tree class have a height setter?

a) height is public

b) height never changes

c) grow() is the setter

d) getHeight() sets it

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

65
New cards

which class acts as the main/client program?

a) inventory

b) forest

c) tree

d) TreePlanter

TreePlanter

66
New cards

which step was ommited from the lecture development process?

a) documentation

b) unit testing

c) uml

d) stub methods

unit testing

67
New cards

what was the final step in the development process followed in the lecture?

uml

unit testing

documentation

coding methods

implementing/coding methods

68
New cards

which of the following types could be stored in a container of WaterMonster?

a) Squiiirtle

b) Starfishy

c) Peekatu

d) Monster

e) ElectricMonster

f) WaterMonster

squirtle, starfishy, watermonster

69
New cards

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

false

70
New cards

which keyword is used to indicate inheritance in java?

extends

71
New cards

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

true or false

true

72
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()

73
New cards

the downside to polymorphism is that you cannot convert an object back to its original type

false

74
New cards

which of the following are a benefit of polymorphism?

a) Reduces coupling

b) Reduces code

c) Simplifies code

d) Increases flexibility

all of the above

75
New cards

which keyword defines a class uses an interface in Java?

a) inherits

b) implements

c) instanceof

d) extends

implements

76
New cards

which of the following data structures in Java can store primitive types?

a) TreeMap

b) ArrayList

c) Array

d) HashSet

Array

77
New cards

An ArrayList uses an Array to store its data, and therefore an ArrayList has a fixed size that must be specified upon creation

false

78
New cards

An Array can only store primitive data types.

false

79
New cards

Both TreeMap and HashMap implement the same Map interface, and can therefore be used interchangeably

true or false

true

80
New cards

Imagine you are creating a role-playing game and need to store all of your inventory items in a collection. You want to be able to look up an item by name, and frequently get a list of all of the item names sorted alphabetically. Which of the following collections would you use?

a) TreeSet

b) TreeMap

c) Hashmap

d) LinkedList

TreeMap

81
New cards

Imagine you are in need of a collection that stores items in a linear structure and will be frequently inserting and deleting from the middle of the collection. Which collection would be the best option?

HashMap

TreeSet

ArrayList

LinkedList

LinkedList

82
New cards

The collections classes, such as LinkedList and TreeMap, are defined using Generic typing.

true or false

true

83
New cards

Generic typing is reserved for classes provided by Java, such as ArrayList. We cannot implement generic typing in custom classes.


False

84
New cards

It is possible to restrict a generic type to a particular supertype, such as a class or an interface type.

true or false

true

85
New cards

The Comparable interface allows different instances of the same class to be comparable using the '<' and '>' operators.

false

86
New cards

By implementing the Comparable interface, Java will automatically generate the rules by which to compare that object.

false

87
New cards

After an exception is caught, the program continues execution where the exception was originally thrown.

false

88
New cards

Which of the following scenarios describe a situation when an exception should be thrown?

a) a user enters bad/incorrect data

b) a test regression fails

c) a bug detected in the program

d) a parameter violates a stated precondition

a user enters bad data, a parameter violates a stated precondition

89
New cards

Where is the best place to catch and handle an exception?

a) the main program

b) the method that has enough information to most effectively handle the exception

c) immediately, the place where the method that threw the exception is originally called

the method that has enough information to most effectively handle the exception

90
New cards

A try-catch statement can catch multiple different types of exceptions from the same try block.

true or false

true

91
New cards

When using the Scanner class' nextInt() method, which of the following exceptions are most likely to be thrown if the user enters something that isn't a number?

a) ArithmeticException

b) InputMismatchException

c) NullPointerException

d) InputMismatchException

InputMismatchException

92
New cards

Which of the following statements about exceptions is true? 

a) A checked exception is named because it indicates a bug that should have been checked over by the programmer

b) Unchecked exceptions are things like IOException and FileNotFoundException

c) Your code will not compile if you don't try to catch a potential checked exception

d) Your code will not compile if you don't try to catch a potential unchecked exception

Your code will not compile if you don't try to catch a potential unchecked exception

93
New cards

Which of the following will create a pop-up dialogue box, prompting the user to enter some text into the program?

a) JOptionPane.showMessageDialogue()

b) JOptionPane.showOptionDialogue()

c) JOptionPane.showConfirmDialogue()

d) JOptionPane.showInputDialogue()

JOptionPane.showInputDialogue()

94
New cards

Which of the following classes in Java Swing represents the application's window?

a) JWindow

b) JFrame

c) JPanel

d) JLabel

b) JFrame

95
New cards

Which of the following is not a JComponent?

JFrame

JPanel

JButton

JLabel

JFrame

96
New cards

Which of the following is a container widget/component?

JButton

JPanel

JLabel

JTextField

JPanel

97
New cards

When creating a graphical user interface, the interface is automatically made visible when the JFrame object is created.

false

98
New cards

JFrame is a Java class, which means we can create a custom window/frame by creating our own custom class which inherits from JFrame.

true or false

true

99
New cards

In the event delegation model, which of the following is a JButton?

Event Source

Event Handler

Event

Listener

Event Source

100
New cards

Assume you want to respond to a button click. Which of the following describes the process?

You create a class that inherits from ActionListener

You create a class that implements the ActionListener interface

You directly bind a method to the button using the 'addMethodBinding()' method

You write a method called 'actionPerformed()' which is automatically bound to the button

You create a class that implements the ActionListener interface