Comp 182 Test #2

Ace your homework & exams now with Quizwiz!

8- Which operator is used to access the properties and methods of an object in Java? a) . b) : c) :: d) >

a) .

25- What is the disadvantage of using recursion? a) It can lead to stack overflow b) It can improve the performance of the code c) It can make the code simpler

a) It can lead to stack overflow

30- What is the time complexity of a recursive function? a) It depends on the implementation of the function b) It is always O(n) c) It is always O(log n)

a) It depends on the implementation of the function

21- What is recursion in Java? a) It is a process in which a method calls itself b) It is a process in which a method calls another method c) It is a process in which a method calls multiple methods

a) It is a process in which a method calls itself

24- What is the advantage of using recursion? a) It simplifies the code b) It improves the performance of the code c) It makes the code more complex

a) It simplifies the code

28- What happens when a recursive function is called with a very large input? a) It will always result in a stack overflow error b) It will always result in an infinite loop c) It depends on the implementation of the function

a) It will always result in a stack overflow error

16- What is the purpose of the constructor method in Java? a) To create a new object b) To define instance variables c) To define class variables d) To define static methods

a) To create a new object

12- Which keyword is used to define a method that has no implementation in Java? a) abstract b) final c) static d) synchronized

a) abstract

5- Which keyword is used to prevent a class from being inherited by other classes in Java? a) final b) private c) protected d) static

a) final

17- Which access modifier allows a class to be accessed from any other class in any package in Java? a) public b) private c) protected d) default

a) public

9- Which access modifier allows a class to be accessed by any other class in any package in Java? a) public b) private c) protected d) default

a) public

29- Which of the following is an example of a recursive function? a) A function that adds two numbers b) A function that calculates the factorial of a number c) A function that sorts an array

b) A function that calculates the factorial of a number

27- Which of the following is true about recursive functions? a) They always have a return statement b) They can have a return statement or not c) They cannot have a return statement

b) They can have a return statement or not

1- Which keyword is used to define a class in Java? a) public b) class c) static d) void

b) class

7- Which method is called when an object is created in Java? a) init() b) constructor() c) start() d) main()

b) constructor()

11- Which method is used to compare two objects for equality in Java? a) compare() b) equals() c) compareTo() d) hashCode()

b) equals()

10- Which access modifier allows a method or variable to be accessed only within the same class in Java? a) public b) private c) protected d) default

b) private

18- Which access modifier allows a method to be accessed only within the same class in Java? a) public b) private c) protected d) default

b) private

6- Which keyword is used to make a method or variable accessible only within the same class in Java? a) public b) private c) protected d) static

b) private

3- Which keyword is used to refer to the current instance of a class in Java? a) current b) this c) that d) instance

b) this

26- Which of the following is not required for a recursive function? a) A base case b) A recursive case c) A loop

c) A loop

23- What is the recursive case in recursion? a) It is the case in which a method stops calling itself b) It is the case in which a method calls itself only once c) It is the case in which a method calls itself multiple times

c) It is the case in which a method calls itself multiple times

22- What is the base case in recursion? a) It is the case in which a method does not call itself b) It is the case in which a method calls itself only once c) It is the case in which a method stops calling itself

c) It is the case in which a method stops calling itself

20- Which keyword is used to inherit properties and methods from a superclass in Java? a) this b) super c) extends d) implements

c) extends

2- Which keyword is used to create an object of a class in Java? a) object b) class c) new d) this

c) new

19- Which keyword is used to access the instance variables and methods of a class in Java? a) static b) final c) this d) super

c) this

15- Which of the following is not a valid Java class name? a) MyClass b) myClass c) MYCLASS d) 123Class

d) 123Class

14- Which of the following is not a feature of a Java class? a) Methods b) Fields c) Objects d) Procedures

d) Procedures

4- Which keyword is used to inherit properties and behaviors from a superclass in Java? a) this b) super c) inherit d) extends

d) extends

13- Which keyword is used to define a method or variable that belongs to the class, rather than to any instance of the class, in Java? a) public b) private c) protected d) static

d) static


Related study sets

Econ 102 Quiz Week 12 - Game Theory

View Set

Emésztőrendszer buktató kérdések

View Set

NSG 320 Chapter 27 Antituberculars, Antifungals, & Antivirals

View Set