OOP Quiz 4 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 = parseInt(“45”);
c. Integer a = new Integer(0); a.parseInt(“45”);
d. Integer a = parseInt(“45”);
e. int a = Integer.parseInt(“45”); Correct
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?
ArrayManipulationApp.changeElement(1,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.)
data = Widget.info;
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
‘length’ is instance-level, and has an initial value of 0
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
There is no return type declared
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
c. 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 = 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.
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
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.
b. Java8.0
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. 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 = s1.equals(s2);
b. boolean b = String.equals(s1,s2);
c. boolean b = (s1==s2);
d. boolean b = (s1 equals s2);
a. boolean b = s1.equals(s2); Correct
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
false