Salakya Test 1 CSCI 185

studied byStudied by 0 people
0.0(0)
get a hint
hint

The job of accessor and mutator methods are

1 / 24

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

25 Terms

1

The job of accessor and mutator methods are

to set and get the values of private instance variables

New cards
2

Encapsulation divides a class into which 2 of the following

implementation, and interface

New cards
3

Which of the following is not true when encapsulating a class definition

We should make helping methods, that are only to be called by other methods public

New cards
4

Which of the following are part of a class interface?

method signatures, and class javadoc comments

New cards
5

Which of the following are the defining principles of OOP programming

encapsulation, interface, polymorphism

New cards
6

A reference type is

a variable that holds references

New cards
7

What type should method that prints a string to the console be?

Cannot use == to compare 2 objects, must write a method that is .equals()

New cards
8

What happens if you compare 2 objects with (p1==p2)

nothing because both objects are not the same

New cards
9

Calling a method that returns a quantity

use anywhere a value can be used

New cards
10

Given a class called student that has a variable name, what would be the appropriate signature of the default constructor

public Student()

New cards
11

What is the purpose of defining and using a constructor

to instantiate an object, provide an object with initial values

New cards
12

What is the default constructor in java class

the constructor defined with no parameters, constructor that is provided to us by java when no other constructor defined

New cards
13

What is a static variable

a variable that belongs to the class itself and not the object

New cards
14

Int[] b = new int[10]

For (int i = 1 ; i <= b.length; i++)

b[i]=5*i;


what will the code do

the program will crash

New cards
15

Consider the following array-

Int[] a = new int[22];

What is the last index of a?


a.length-1 and 21


New cards
16

Given 

Int[] numbers = new double[8];

numbers[2]=22.6;


What is the correct term for ‘numbers’?


 array, array variable

New cards
17

The search algorithm that looks through each element in an array, in order, until a result is found is called

Sequential search


New cards
18

Which of the following are names for sorting algorithms

Selection sort, bogo sort


New cards
19

What are the purpose of accessor and mutator methods? When is it appropriate to use them? The act of adding these types of methods enables better what of our code?:


Set and get the values of the variables. We should always make them private. Better encapsulation of our code


New cards
20

What is a reference type? Are class objects reference types? Are primitive types such as int and double reference types?

Class objects are reference types. No

New cards
21

What is a foreach loop? How does it differ from a regular for loop? What structures, that we learned in class, can we use a foreach loop on? Suppose we had an object called Student. Create an array of students of size 10, use a foreach loop to iterate over that array. For each item in the array call the method writeOutput(); (you can assume that the method writeOutput() exists, is void, and is a method that belongs to the Student class()

it is a type of forloop, different because it doesn't have a variable condition or update statement, we used it in arrays

New cards
22

Int[] anArray = new int[15];

for(int i0; i< anArray.length; i++);

anArray[i] = 4*i;

For (int i=anArray.length-2; i>=0; i-=3)

System.out.print(anArray[i]+ “ “); 


creating an array of 15 integers


going through whole array


0/0 4/1 8/2 12/3 16/4 20/5 24/6 28/7 32/8 36/9 40/10 44/11 48/12 52/13 56/14


New cards
23

Trace the steps that a selection sort takes as it sorts the following array into ascending order-

16 31 19 18 67 45 15


16 and 15 swap: 15 31 19 18 67 45 15

31 and 16 swap: 15 16 19 18 67 45 31

19 and 18 swap: 15 16 18 19 67 45 31

19 swaps with itself: 15 16 18 19 67 45 31

67 and 31 swap: 15 16 18 19 31 45 67

45 swaps with itself: 15 16 18 19 45 67


New cards
24
New cards
25
New cards

Explore top notes

note Note
studied byStudied by 14 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 93 people
Updated ... ago
5.0 Stars(3)
note Note
studied byStudied by 195 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 28 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 4830 people
Updated ... ago
4.8 Stars(21)

Explore top flashcards

flashcards Flashcard40 terms
studied byStudied by 27 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard71 terms
studied byStudied by 9 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard106 terms
studied byStudied by 7 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard31 terms
studied byStudied by 189 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard56 terms
studied byStudied by 5 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard80 terms
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard50 terms
studied byStudied by 21 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard182 terms
studied byStudied by 11 people
Updated ... ago
5.0 Stars(1)