Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1 When a method returns an array reference, you include ____ with the r

ID: 3581202 • Letter: Q

Question

Question 1                                                                                                                                

When a method returns an array reference, you include ____ with the return type in the method header.

{ }

( )

< >

[ ]

Question 2                                                                                                                                

Assuming a variable w has been assigned the value 15, what does the following statement do? w==15 ? x=2: x=0

assigns 2 to x

assigns 15 to w

assigns 0 to x

nothing

Question 3                                                                                                                                

Each of the following is a relational or equality operator except:

<=

=!

==

>

Question 4                                                                                                                                

A method is declared as public static void showResults(double d, int i). Which of the following is a correct method call?

showResult(double d, int i)

showResult(4, 99.7)

showResult(12.2, 67)

showResult(12.2, 99.7)

Question 5                                                                                                                                

The ____ statement is useful when you need to test a single variable against a series of exact integer, character, or string values.

switch

if

else

break

Question 6                                                                                                                                

What is the output of the following Java code?

int x = 0 if (x > 0)

System.out.println("positive ") System.out.println("zero ")

System.out.println("negative")

zero

negative

zero negative

positive zero negative

Question 7                                                                                                                                

When any ____ type (boolean, char, byte, short, int, long, float, or double) is passed to a method, the value is passed.

array

dummy

element

primitive

Question 8                                                                                                                                

Which of the following statements are true about constructors of a class? (Choose all that apply)

You can only define one constructor.

Constructors do not have a return type.

Constructors must have the same name as the class itself.

Constructors are invoked using the new operator when an object is created.

Question 9                                                                                                                                

Which of the following are correct names for variables according to Java naming conventions? (Choose all that apply)

radius

Radius

RADIUS

findArea

Question 10                                                                                                                              

A variable defined inside a method is referred to as __________.

a global variable

a method variable

a block variable

a local variable

Question 11                                                                                                                              

public static char methodHeading(int n, double num)

Which of the following statements about the method heading in the accompanying figure is NOT true?

The method has two parameters.

The method cannot be used outside the class.

methodHeading is an identifier giving a name to this specific method.

It is a value­returning method of type char.

Question 12                                                                                                                              

A(n) ____ method is a method that creates and initializes class objects.

constructor

accessor

non­static

instance

Question 13                                                                                                                              

Which of the following is incorrect? (Choose All that apply)

int[] a = new int[2]

int a() = new int[2]

int[] a = new int(2)

int a = new int[2]

Question 14                                                                                                                              

The ____ requires three expressions separated with a question mark and a colon.

flowchart

conditional operator

sequence structure

conditional statement

Question 15                                                                                                                              

Which of the following is NOT true about return statements?

A value­returning method returns its value via the return statement.

return statements can be used in void methods to return values.

A method can have more than one return statement.

Whenever a return statement executes in a method, the remaining statements are skipped and the method exits.

Question 16                                                                                                                              

Calling a method has the ability to take many forms is called ________.

inheritance

polymorphism

encapsulation

abstraction

Question 17                                                                                                                              

Which method contains the code that the program executes when a specific event is generated?

buttonListener

GUIListener

actionPerformed

windowListener

Question 18                                                                                                                              

Any of the file input or output methods in a Java program might throw an exception, so all the relevant code in the class is placed in a ____ block.

finally

throw

try

catch

Question 19                                                                                                                              

The JCheckBox, JComboBox, and JRadioButton components are associated with the ____ method.

addAdjustmentListener()

addChangeListener()

addWindowListener()

addItemListener()

Question 20                                                                                                                              

Inheritance is an example of what type of relationship?

is­a

has­a

was­a

had­a

Question 21                                                                                                                              

The method __________ sets the font (Helvetica, 20­point bold) in component C.

c.setFont(new Font("Helvetica", Font.bold, 20))

c.setFont(new Font("helvetica", BOLD, 20))

c.setFont(Font("Helvetica", Font.BOLD, 20))

c.setFont(new Font("Helvetica", Font.BOLD, 20))

Question 22                                                                                                                              

To specify an italic font, you pass ____ to the constructor.

Font.ITALIC

Font.BOLD

PLAIN.ITALIC

ITALIC

Question 23                                                                                                                              

Which class do you use to read data from a text file?

File

Formatter

Scanner

Input

Question 24                                                                                                                              

An attribute that is shared by all objects of the class is coded using _____________.

an instance variable

a static instance variable

an instance method

a static method

Question 25                                                                                                                              

Usually, the subclass constructor only needs to initialize the ____ that are specific to the subclass.

objects

data fields

methods

constructors

Question 26                                                                                                                              

When you instantiate an object from a class, ____ is reserved for each instance field in the class.

a constructor

a signature

memory

a field name

Question 27                                                                                                                              

Select appropriate method out of number of methods' definitions at execution time is called _______.

Compiling

Static binding

Dynamic binding

Matching

Question 28                                                                                                                              

An abstract class can contain ____.

only abstract methods

only non­abstract methods

abstract and non­abstract methods

nothing

Question 29                                                                                                                              

When you create a class and do not provide a(n) ____, Java automatically supplies you with a default one.

constructor

argument

header

name

Question 30                                                                                                                              

Which of the following is used to allocate memory for the instance variables of an object of a class?

the reserved word public

the reserved word static

the operator new

the operator +

Question 31                                                                                                                              

Which of the following correctly declares and initializes a String object?

new String = Hello

String greeting == "Hello"

String greeting = "Hello"

String new = "Hello"

Question 32                                                                                                                              

Imageobjects are displayed using which Graphicsmethod?

drawImage.

paintImage.

getImage.

setImage.

Question 33                                                                                                                              

What layout manager should you use so that every component occupies the same size in the container?

a FlowLayout

a GridLayout

a BorderLayout

any layout

Question 34                                                                                                                              

When an object of one class is a data field within another class, they are related by ____.

extension

scope

composition/has­a

is­a

Question 35                                                                                                                              

The ____ method takes a String argument and returns its double value.

parseString()

parseInt()

parseDouble()

returnDouble()

Question 36                                                                                                                              

The compiler determines which version of a method to call by the method’s ____.

name

signature

output

constructor

Question 37                                                                                                                              

Which JFrameJFrame method is used to display the frame?

Display().

Load().

setVisible(true)

show(true)

Question 38                                                                                                                              

___________ can be used to enter or display a string.

A label

A button

A check box

A radio button

A text field

Question 39                                                                                                                              

The ____ method creates a solid arc.

solidArc()

fillArc()

clearArc()

drawArc()

Question 40                                                                                                                              

Which method can be used to create an input object for file temp.txt?

new Scanner("temp.txt")

new Scanner(temp.txt)

new Scanner(Paths.get("temp.txt"))

new Scanner(Path("temp.txt"))

Question 41

Assume s is " abc

", the method __________ returns a new string "abc".

s.trim(s)

trim(s)

String.trim(s)

s.trim()

Question 42                                                                                                                              

What happens in a method if there is an exception thrown in a try block but there is no catch block following the try block?

The program ignores the exception.

The program will not compile without a complete try/catch structure.

The program terminates immediately.

The program throws an exception and proceeds to execute the finally block.

Question 43                                                                                                                              

Which of the following words indicates an object’s reference to itself?

this

that

public

protected

Question 44                                                                                                                              

Suppose s is a string with the value "java". What will be assigned to x if you execute the following code? char x = s.charAt(4)

"a"

"v"

Nothing due to a runtime error StringIndexOutofBoundsException

"java"

Question 45                                                                                                                              

____ variables are variables that are shared by every instantiation of a class.

Local

Instance

Class/Static

Time

Question 46                                                                                                                              

Which of the following statements starts a polygon named pol at the coordinates 20 and 290?

pol.moveTo(20F, 290F)

pol.lineTo(20F, 290F)

pol = new Path(20F, 290F)

pol.newPath(20F, 290F)

Question 47                                                                                                                              

Suppose str is a String variable. The statement

str = new String("Programming")

is similar to which of the following?

new String = "Programming"

String new = "Programming"

str = "Programming"

str new "Programming"

Question 48                                                                                                                              

The ____ method requires four arguments and draws the outline of a rectangle using the current drawing color.

clearRect()

drawRect()

fillRect()

paintRect()

Question 49                                                                                                                              

Which of the following is a valid statement?

int num = new int(67)

String name = new ("Doe")

String name = "Doe"

Only (i)

Only (i) and (ii)

Only (iii)

Only (ii) and (iii)

Question 50                                                                                                                              

Which of the following generates GUI events?

Typing in a text field.

Selecting an item from a menu.

Click on a button

All of above

Explanation / Answer

1. ( )

2. assigns 2 to x

3. ==

4. showResult(12.2, 67)

5. if

6. System.out.println("positive ") System.out.println("zero ")

7. primitive

8.Constructors must have the same name as the class itself.

Constructors are invoked using the new operator when an object is created.

9. RADIUS

findArea

10. It is a value­returning method of type char.

11. methodHeading is an identifier giving a name to this specific method.

12. instance

13. int[] a = new int[2]

14. conditional operator

15. A method can have more than one return statement.

16. inheritance

17. actionPerformed

18. catch

19. addItemListener()

20. is­a

21. c.setFont(new Font("Helvetica", Font.BOLD, 20))

22. Font.ITALIC

23. Scanner

24. a static instance variable

25. methods

26. memory

27. Static binding

28. abstract and non­abstract methods

29. constructor

30. the operator new

31. String new = "Hello"

32. drawImage

33. a BorderLayout

34. composition/has­a

35. parseDouble()

36. signature

37. Display().

38. A text field

39. fillArc()

40. new Scanner(temp.txt)

41. s.trim()

42. The program will not compile without a complete try/catch structure.

43. this

44. Nothing due to a runtime error StringIndexOutofBoundsException

45. Class/Static

46.

47. str = "Programming"

48. clearRect()

49. Only (i) and (ii)

50.Typing in a text field.

Selecting an item from a menu.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote