OOP Quiz 5 Flashcards
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”);
b. int a = Integer.parseInt(“45”);
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
5 56
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
data = Widget.info;
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
club
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”);
c. int a = Integer.parseInt(“45”);
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
true
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. float[] marks = {67.5f, 57.5f, 90.0f};
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);
b. boolean b = s1.equals(s2);
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
false