22. ________ is invoked to create an object. a. A constructor b. The main method c. A method with a return type d. A method with the void return type
Author: Anonymous
21. Analyze the following code: public class Test { publ…
21. Analyze the following code: public class Test { public static void main(String[] args) { A a = new A(); a.print(); } } class A { String s; A(String s) { this.s = s; } void print() { System.out.println(this.s); } } a. The program has a compile error because class A is not a public class. b. The program has a compile error because class A does not have a default constructor. c. The program would compile and run if you change A a = new A() to A a = new A(“5”). d. option a and c e. option b and c
15. Which of the following statements are true? a. Data fiel…
15. Which of the following statements are true? a. Data fields do not have default values. b. Local variables have default values. c. A variable of a primitive type holds a reference to the value of the primitive type. d. A variable of a reference type holds a reference to where an object is stored in the memory. e. All of the above.
4. If you declare an array double[] list = {3.4, 2, 3, 5.5},…
4. If you declare an array double[] list = {3.4, 2, 3, 5.5}, list[1] is ________. a. 3.4 b. 2 c. 3 d. 2.0 e. None of the above
25. A method that is associated with an individual object is…
25. A method that is associated with an individual object is called ________. a) an object method b) a static method c) an instance method d) a class method
q34. What is the output of the code?
q34. What is the output of the code?
24. Variables that are shared by every instances of a class…
24. Variables that are shared by every instances of a class are ________. a) static variables b) public variables c) instance variables d) private variables
5. What is the output of the following code? a. 56 b. 67 c…
5. What is the output of the following code? a. 56 b. 67 c. 5 d. 6 e. None of the above
13. How can you initialize an array of two characters to ‘a’…
13. How can you initialize an array of two characters to ‘a’ and ‘b’? a. char[] charArray = new char[2]; charArray = {‘a’, ‘b’}; b. char[2] charArray = {‘a’, ‘b’}; c. char[] charArray = {‘a’, ‘b’}; d. all of the above
24. Variables that are shared by every instances of a class…
24. Variables that are shared by every instances of a class are ________. a) static variables b) public variables c) instance variables d) private variables