





































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
All the quizzes throughout the semester.
Typology: Quizzes
1 / 45
This page cannot be seen from the preview
Don't miss anything!






































State Finished Time taken 1 hour 1 min Marks 63.12/71. Grade 88.90 out of 100.
Partially correct Mark 0.20 out of 1. Flag question Question text What does the computer do when it executes the following statement? Color[] pallette = new Color[12]; Select one or more: a. This is a declaration statement, that declares and initializes a variable named pallette of type Color[]. b. The initial value of this variable is a newly created array that has space for 12 items. c. The computer creates a new 12-element array object on the heap, and it fills each space in that array with null. d. The computer allocates a memory space for the variable, pallette. e. It stores a pointer to the new array object in that memory space.
Correct Mark 1.00 out of 1. Flag question Question text
What is the relationship between objects of class Button and ActionEvents? a. When a button is clicked, it generates an event. This event is represented by an object of type ActionEvent. b. This object is passed to the actionPerformed method of any ActionListener that has been registered to listen for action events from the button. c. ActionEvents are part of the mechanism that is used to make some action occur when a button is clicked. Select one or more: a. a. b. b. c. c. Feedback Your answer is correct.
Correct Mark 1.00 out of 1. Flag question Question text In which of the following examples can a NumberFormatException occur?
Select one: a. When an attempt is made to convert a string into a number. b. In the valueOf function of an enumerated type. c. If an attempt is made to read from a file after all the data in the file has already been read. d. When TextIO.readfile is used to open a file that does not exist.
Flag question Question text The method … places a menu item mi into a menu mu. Select one: a. mu.add(mi) b. mu.addMenuItem(mi) c. mu.addItem(mi) d. None of the above.
Correct Mark 1.00 out of 1. Flag question Question text What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = "Welcome to Java!"; String s2 = s1; if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); } } Select one: a. s1 and s2 reference to the same String object
b. s1 and s2 reference to different String objects Feedback Your answer is correct.
Correct Mark 1.00 out of 1. Flag question Question text Consider the following code: public class Test { public static void main(String[] args) { int[] x = {1, 2, 3, 4}; int[] y = x; x = new int[2]; for (int i = 0; i < y.length; i++) System.out.print(y[i] + " "); } } Select one: a. The program displays 1 2 3 4 b. The program displays 0 0 c. The program displays 0 0 3 4 d. The program displays 0 0 0 0 Feedback Your answer is correct.
Correct Mark 1.00 out of 1.
Flag question Question text True or False: The do-while loop repeats a set of code at least once before the condition is tested. Select one: True False
Incorrect Mark 0.00 out of 1. Flag question Question text True or False: A program that is written in the Java programming language must be compiled before it can be executed. Select one: True False
Correct Mark 1.00 out of 1. Flag question Question text What is the printout of the third println statement in the main method?
public class Foo { int i; static int s; public static void main(String[] args) { Foo f1 = new Foo(); System.out.println("f1.i is " + f1.i + " f1.s is " + f1.s); Foo f2 = new Foo(); System.out.println("f2.i is " + f2.i + " f2.s is " + f2.s); Foo f3 = new Foo(); System.out.println("f3.i is " + f3.i + " f3.s is " + f3.s); } public Foo() { i++; s++; } } Select one: a. f3.i is 1 f3.s is 1 b. f3.i is 1 f3.s is 2 c. f3.i is 1 f3.s is 3 d. f3.i is 3 f3.s is 1 e. f3.i is 3 f3.s is 3 Feedback Your answer is correct.
Incorrect Mark 0.00 out of 1. Flag question Question text The operation ++ in Java means: Select one: a. That the value of 1 is added to the variable b. That the program should start executing from the beginning
b. 20 c. 30 d. 40 Feedback Your answer is correct.
Partially correct Mark 0.75 out of 1. Flag question Question text Which of the following statements are true? Select one or more: a. Inner classes can make programs simple and concise. b. An inner class can be declared public or private subject to the same visibility rules applied to a member of the class. c. An inner class can be declared static. A static inner class can be accessed using the outer class name. A static inner class cannot access nonstatic members of the outer class. d. An inner class supports the work of its containing outer class and is compiled into a class named OuterClassName$InnerClassName.class. Feedback Your answer is partially correct. You have correctly selected 3.
Correct Mark 1.00 out of 1.
Flag question Question text Here is the definition of the Pythagoras function: static double Pythagoras (double x, double y) { // Computes the length of the hypotenuse of a right // triangle, where the sides of the triangle are x and y. return Math.sqrt( xx + yy ); } Now, what is the result of the following statement: totalLength = 17 + Pythagoras (12,5); Select one: a. 10 b. 60 c. 30 d. 35 Feedback Your answer is correct.
Correct Mark 1.00 out of 1. Flag question Question text When you return an array from a method, the method returns … Select one: a. A copy of the array
Correct Mark 1.00 out of 1. Flag question Question text True or False: Can a for statement loop indefinitely? Select one: True False
Correct Mark 1.00 out of 1. Flag question Question text How many items can be added into a JComboBox object? Select one: a. 1 b. 3 c. 2 d. No limit
Correct Mark 1.00 out of 1. Flag question
Question text Show the exact output produced by the following code segment. char[][] pic = new char[6][6]; for (int i = 0; i < 6; i++) for (int j = 0; j < 6; j++) { if ( i == j || i == 0 || i == 5 ) pic[i][j] = '*'; else pic[i][j] = '.'; } for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) System.out.print(pic[i][j]); System.out.println(); a.
..... ..... ..... .....
b.
..... ..... ..... .....
c. ...... ..... ..... ..... .....
d.
..... ..... ..*...
area = 3.14159 * (radius + radius); System.out.println( "The area of a circle of radius " + radius + " is " + area ); } } c. public class Area { public static void main(String[] args) { double area; area = 3.14159 * radius + 17.42 * radius; System.out.println( "The area of a circle of radius " + radius
Correct Mark 1.00 out of 1. Flag question Question text
Suppose that the first line of a subroutine definition is: static void test(int n, double x). Now consider these statements: test(17,42) test(0.17,3.227) Which of those statements is a legal subroutine call? Select one: a. Both 1 and 2 b. 1 c. 2 d. Neither 1 nor 2
Correct Mark 1.00 out of 1. Flag question Question text Show the contents of the array A after the following code has been executed: int[] A; A = new int[7]; A[0] = 1; A[1] = 1; for (int i = 2; i < 7; i++) { A[i] = A[i-1] + A[i-2]; } a. A[0] = 1 A[1] = 1 A[2] = 2 A[3] = 3 A[4] = 5
c. an instance method d. an object method
Correct Mark 1.00 out of 1. Flag question Question text Suppose that a class definition begins: public class QuizQuestion { public int firstNum, secondNum; ... Which statements are correct?
Correct Mark 1.00 out of 1.
Flag question Question text Object-oriented programming allows you to derive new classes from existing classes. This capability is known as: Select one: a. Encapsulation b. Abstraction c. Generalization d. Inheritance
Correct Mark 1.00 out of 1. Flag question Question text A static member variable that is declared to be final can be termed a named constant , since its value remains constant for the whole time that the program is running. For example, if the member variable pulse is declared with: final static double pulse = 90.5; It is impossible to assign any other value to pulse within the confines of the program. Select one: True False