question archive 1 ) Select the statement that would correctly instantiate the array below to have 4 rows and 8 columns? String[][] vals; - vals[4][8]; - vals = new String[8][4]; - vals[8][4]; - vals = new String[4][8]; - vals = new char[4][8]; 2 ) Select all methods from the class below that are mutators
Subject:Computer SciencePrice: Bought3
1 ) Select the statement that would correctly instantiate the array below to have 4 rows and 8 columns?
String[][] vals;
- vals[4][8];
- vals = new String[8][4];
- vals[8][4];
- vals = new String[4][8];
- vals = new char[4][8];
2 ) Select all methods from the class below that are mutators.
public class Person {
String name;
int age;
public void setName( String n ){
name = n;
}
public String getName( ) {
return name;
}
public int getAge( ) {
return age;
}
public void setAge( int a ) {
age = a;
}
}
- setName
- getName
- Person
- getAge
- setAge
3 ) Select all of the following statements which correctly assign a value (WITHOUT ERROR) to an index in the 2D array below.
int[][] vals = new int[2][5];
- vals[0][3] = 8;
- vals[0] = 6;
- vals[1][4] = -9;
- vals[1][5] = -8;
- vals[2][3] = 7;
4 ) Select all methods from the class below that are accessors.
public class Foursquare{
int x;
int y;
public void setX(int value){
x = value;
}
public void setY(int value){
y = value;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
}
- getY
- setX
- getX
- setY
5 ) If there is a Person variable named p, select all valid method calls using that variable.
public class Person {
String name;
int age;
public void setName( String n ){
name = n;
}
public String getName( ) {
return name;
}
public int getAge( ) {
return age;
}
public void setAge( int a ) {
age = a;
}
}
- getName( p )
- p.setAge( )
- p.setName( "Veronica" )
- p.getAge
- p.getName()
6 ) Convert the decimal number -10 to binary 2s complement representation. Express your answer in 5 digits with no spaces.
7 ) What is printed by the class' main method below?
public class Apartment {
int numOfFloors;
public int getFloors(){
return numOfFloors;
}
public void setFloors(int number){
numOfFloors = number;
}
public addFloors(int count){
numOfFloors += count;
}
public void main(String[] args){
Apartment a1 = new Apartment();
a1.setFloors(20);
Apartment a2 = new Apartment();
a2.setFloors(18);
Apartment a3 = a2;
a3.addFloors(6);
System.out.println(a1.getFloors());
}
}
- 18
- 24
- 17
- 26
- 20
8 ) Select all of the primitive variable declarations below.
- Scanner words;
- int x;
- String str;
- double interest;
- boolean isName;
9 ) If there is a Bicycle variable named b, select all valid method calls using that variable.
public class Bicycle {
public int cadence;
public int speed;
public void setCadence(int value){
cadence = value;
}
public int getCadence(){
return cadence;
}
public void setSpeed(int value){
speed = value;
}
public int getSpeed(){
return speed;
}
}
- b.setSpeed()
- b.setSpeed(100)
- setCadence(b)
- b.getCadence(10)
- b.getCadence()
10 ) If the following bit pattern is interpreted to be an unsigned integer, what is its decimal equivalent? Express your answer in digits
1011
11 ) Select all class-type variable declarations below.
- int count;
- Turtle greenTurtle;
- String street;
- char initial;
12 ) A class method which changes a data field (or instance variable) is called a(n)...
- accessor
- class
- keyword
- constructor
- mutator
13 ) Which of the following expressions evaluate to 12 for the 2D array below?
int[][] vals = new int[2][12];
- vals[0].length
- vals.length
- vals
- vals[12]
14 ) Which of the following are used to format a floating point number
- significand
- exponent
- sign
- identity
- property
15 ) What type of exception needs to be handled by your code when reading a file
- FileNotFoundException
- IOException
- ParseException
StringIndexOutOfBoundsException
- NullPointerException
16 ) A unit of user input separated by whitespace is called a(n) _________.
- token
- chunk
- line
- symbol
- keyword
17 ) When debugging, what option would you want to use if you go into the first line of the code of a method that has just been called
- bugging
- step out
- method step
- resume
- step into