OOP Quiz 5 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 = Integer.parseInt(“45”);
c. Integer a = new Integer(0); a.parseInt(“45”);
d. int a = parseInt(“45”);
e. Integer a = parseInt(“45”);

A

b. 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? Choose one of the options provided.

ArrayManipulationApp.changeElement(1,56);

Select one:
exit with exception at runtime
5 5

3 3
3 then exit with exception at runtime
5 then exit with exception at runtime
5 56 
compilation error
3 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.)

Select one:
data = Widget.info;
Widget.info = data;
data = Widget.info();
data = info;
Widget.info(data);
You cannot access the info field outside of Widget
A

data = Widget.info;

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

See the following source file CardApp.java:

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. heart
c. spade
d. club

A

club

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
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 = parseInt(“45”);
b. int a = int.parseInt(“45”);
c. int a = Integer.parseInt(“45”);
d. None is correct.
e. Integer a = new Integer(0); a.parseInt(“45”);

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
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
7
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(3); marks[0]=67.5f; marks[1]=57.5f; marks[2]=90.0f;
c. float marks[]=new float {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 = {67.5f, 57.5f, 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
8
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 = String.equals(s1,s2);
b. boolean b = s1.equals(s2);
c. boolean b = (s1==s2);
d. boolean b = (s1 equals s2);

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
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:
true
false

A

false

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