OOP Quiz 4 Flashcards

1
Q

There is a method in the ‘Integer’ class:

Public static int parseInt(String s)

What’s the correct way to covert a string into an integer variable?

Select one:

a. int a = int.parseInt(“45”);
b. int a = parseInt(“45”);
c. Integer a = new Integer(0); a.parseInt(“45”);
d. Integer a = parseInt(“45”);
e. int a = Integer.parseInt(“45”); Correct

A

int a = Integer.parseInt(“45”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Consider the class ArrayManipulationApp defined below.

public class ArrayManipulationApp {
	private static final int[] array = new int[] {3,5};
	public static void changeElement(int index, int value){
		System.out.print(array[index]);
		System.out.print(" ");
		array[index] = value;
		System.out.print(array[index]);
	}
}

What is printed to the terminal window as a result of compiling and running code containing the following statements?

ArrayManipulationApp.changeElement(1,56);

A

5 56

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

If the class Widget has a public static String attribute called info, how would this be accessed outside of the Widget class to assign its value to an identifier called data that has previously been declared as being of type String? (Assuming the Widget class file is accessible.)

A

data = Widget.info;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The following field has been declared as a member of a Java class.
int length;
Which of the following is correct?
Select one:
‘length’ is class-level, and has an initial value of 0
‘length’ is class-level, and has an unknown initial value
‘length’ is instance-level, and has an unknown initial value
‘length’ is instance-level, and has an initial value of 1
‘length’ is instance-level, and has an initial value of 0
‘length’ is class-level, and has an initial value of 1

A

‘length’ is instance-level, and has an initial value of 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When writing a class, what is the return type declared in the signature of its constructor?

Select one:
There is no return type declared
void
The type being constructed

A

There is no return type declared

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
class Card{
	public String suit;
	public Card(String suit) { this.suit = suit; }
}
public class CardApp{
	public static void main(String[] args){
		Card card1 = new Card("heart");
		changeSuit(card1);
		System.out.println(card1.suit);
	}
	public static void changeSuit(Card card){
		card.suit = "club";
		card = new Card("spade");
	}
}

What will be printed on the screen after executing the program?

Select one:

a. None is correct
b. spade
c. club
d. heart

A

c. club

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
There is a method in the ‘Integer’ class:
Public static int parseInt(String s)
What’s the correct way to covert a string into an integer variable?
Select one:
a. int a = Integer.parseInt(“45”);
b. int a = int.parseInt(“45”);
c. int a = parseInt(“45”);
d. Integer a = new Integer(0); a.parseInt(“45”);
e. None is correct.
A

int a = Integer.parseInt(“45”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
Consider the Java code block below
Integer i = 20;
Integer j = 20;
boolean v = (j==i);
What value is held in the variable v after the statements are processed?
Select one:
false
true
A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
String st = “Java8.0”;
st.toUpperCase().replace('8',’9’);
What does the variable ‘st’ hold after executing the above codes?
Select one:
a. JAVA8.0
b. Java8.0
c. JAVA9.0
d. Java9.0
e. None is correct.
A

b. Java8.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of the following is a correct way of creating an array?

Select one:

a. float[] marks = {67.5f, 57.5f, 90.0f};
b. float marks[]=new float {67.5f, 57.5f, 90.0f};
c. float []marks = new float[3]; marks = {67.5f, 57.5f, 90.0f};
d. float marks[3]; marks[0]=67.5f; marks[1]=57.5f; marks[2]=90.0f;
e. float [] marks = new float(3); marks[0]=67.5f; marks[1]=57.5f; marks[2]=90.0f;

A

a. float[] marks = {67.5f, 57.5f, 90.0f};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

There are two string objects s1 and s2. The desirable method of checking if two strings are equal is:

Select one:

a. boolean b = s1.equals(s2);
b. boolean b = String.equals(s1,s2);
c. boolean b = (s1==s2);
d. boolean b = (s1 equals s2);

A

a. boolean b = s1.equals(s2); Correct

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Consider the Java code block below
Integer i = 200;
Integer j = 200;
boolean v = (j==i);

What value is held in the variable v after the statements are processed?
Select one:
false
true

A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly