CPT test

Your page rank:

Total word count: 1023
Pages: 4

Calculate the Price

- -
275 words
Looking for Expert Opinion?
Let us have a look at your work and suggest how to improve it!
Get a Consultant

Arguments to methods always appear within ________.

parentheses

Each Java class must contain a main method.

false

A ________ method does not return a value.

void

Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as ________, which stores elements in last-in first-out fashion.

a stack

Variables defined inside a method are called ________.

local variables

Which of the following is not an advantage of using methods?

Using methods makes programs run faster.

You may have a return statement in a void method.

true

The actual parameters of a method must match the formal parameters in type, order, and number.

true

You can define two methods in the same class with the same name and parameter list.

false

The signature of a method consists of ________.

method name and parameter list

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

a local variable

You can redeclare the variable if it is declared in the method signature.

false

________ is a simple but incomplete version of a method.

A stub

Java allows you to declare methods with the same name in a class. This is called ________.

method overloading

A method can be declared with no parameters.

true

ou must have a return statement in a non-void method.

true

The modifiers and return value type do not contribute toward distinguishing one method from another, only the parameter list.

true

Which of the following is the best for generating random integer 0 or 1?

(int)(Math.random() + 0.5)

A return statement without any value can be used in ________.

void method

A variable or a value listed in a call to a method is called ________.

an argument

(int)(Math.random() * (65535 + 1)) returns a random number ________.

between 0 and 65535

Methods can be declared in any order in a class.

true

Which of the following should be defined as a void method?

Write a method that prints integers from 1 to 100.

What is the output, if you run the program using the following?

java Test 1 2 3

1 2 3

The reverse method is defined in the textbook. What is list1 after executing the following statements?

int[] list1 = {1, 2, 3, 4, 5, 6};
list1 = reverse(list1);

list1 is 6 5 4 3 2 1

The ________ method copies the sourceArray to the targetArray.

System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);

What is the representation of the third element in an array called a?

a[2]

Which code fragment would correctly identify the number of arguments passed via the command line to a Java application, excluding the name of the class that is being invoked?

int count = args.length;

The reverse method is defined in this section. What is list1 after executing the following statements?
int[] list1 = {1, 2, 3, 4, 5, 6};
int[] list2 = reverse(list1);

list1 is 1 2 3 4 5 6

The array index of the first element in an array is 0.

true

If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is ________.

3

Assume int[] t = {1, 2, 3, 4}. What is t.length?

4

How many elements are in array double[] list = new double[5]?

5

The name length is a method in an array.

false

x.length does not exist if x is null.

true

An array can be used in which of the following ways?

All of these

Which correctly creates an array of five empty Strings?

String[] a = {"", "", "", "", ""};

Suppose array a is int[] a = {1, 2, 3}, what is a[0] – a[2]?

-2

When you pass an array to a method, the method receives ________.

the reference of the array

Assume the signature of the method xMethod is as follows.

public static void xMethod(double[] a)

xMethod(new double[2]);

The element in the array must be of a primitive data type.

false

Which of the following are valid array declarations?

char[] charArray = new char[26];

You can use the operator == to check whether two variables refer to the same array.

true

If a key is not in the list, the binarySearch method returns ________.

-(insertion point + 1)

If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ________.

2.0

The array index is not limited to int type.

false

You use the ________ operator to access members of an object.

.

You can declare variables of the same name in a method if they are in non-nesting blocks.

true

A static data field can be accessed from any method in the same class.

true

Given the declaration Circle[] x = new Circle[10], which of the following statement is most accurate?

x contains a reference to an array and each element in the array can hold a reference to a Circle object.

Given the declaration Circle x = new Circle(), which of the following statement is most accurate?

x contains a reference to a Circle object.

________ represents an entity in the real world that can be distinctly identified.

An object

Array variable are reference variables.

true

A method that is associated with an individual object is called ________

an instance method

To prevent a class from being instantiated, ________.

use the private modifier on the constructor

If the parameter is of a primitive type, both formal parameter and actual parameter reference to the same memory.

false

The default value for data field of a boolean type, numeric type, object type is ________, respectively.

false, 0, null

You use underline to denote static variables and methods.

true

To declare a constant MAX_LENGTH as a member of the class, you write ________

final static double MAX_LENGTH = 99.98;

All data fields in an object have default values.

true

You can always use the default constructor even though the non-default constructors are defined in the class.

false

The default constructor has no arguments.

true

A constructor can access ________.

a private instance variable a public instance variable a static variable

The keyword ________ is required to declare a class.

class

A static method in a class can access the instance variables in the same class.

false

______ is a construct that defines objects of the same type.

A class

Java assigns a default value to a local variable in a method if the variable is not initialized.

false

The default value null is assigned to a data member of object type, even though the data member is not created yet.

true

An immutable class cannot have ________.

public data fields

The default value for a data member of boolean type is true.

false

Share This
Flashcard

More flashcards like this

NCLEX 10000 Integumentary Disorders

When assessing a client with partial-thickness burns over 60% of the body, which finding should the nurse report immediately? a) ...

Read more

NCLEX 300-NEURO

A client with amyotrophic lateral sclerosis (ALS) tells the nurse, "Sometimes I feel so frustrated. I can’t do anything without ...

Read more

NASM Flashcards

Which of the following is the process of getting oxygen from the environment to the tissues of the body? Diffusion ...

Read more

Unfinished tasks keep piling up?

Let us complete them for you. Quickly and professionally.

Check Price

Successful message
sending