csc

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Formal parameters are those that appear in the method call and actual parameters (also called as arguments)are those that appear in the method header. True False

False Formal parameters are what appear in the method header. (public static void aMethod(int parameter) Parameters are the parameters that are passed to the method in the method call (aMethod(myInt);)

When an array of objects is declared but not initialized, the array values are set to 0. True False

False Values are set to null by default.

What happens when an Array is passed to a method? 1.) The method has direct access to the original Array 2.) The Array is passed as any other object would be passed 3.) A reference to the Array is passed 4.) All of the Above

4.) All of the above

In memory, an array of String objects ________. 1.) Is compressed to 4 bytes for each element 2.) Consists of elements, each of which is a ref to a String object 3.) Must be initialized when the Array is declared 4.) Consists of an Array of references to String objects

4.) Consists of an Array of references to String objects.

What method of Enumerated types will return the position of an enum constant in the list? toString position ordinal location

ordinal

The only limitation that static methods have is ________. they can refer only to nonstatic members of the class they cannot refer to nonstatic members of the class they must be declared outside of the class they can only be called from static members of the class

they cannot refer to nonstatic members of the class

Which XXX is needed for enterNumber() to read a value from standard input? public int enterNumber() XXX{int value;value = System.in.read();return value;}

throws IOException

Each of the numeric wrapper classes has a static ________ method that converts a number to a string. GetString Parse toString Convert

toString

Look at the following declaration: enum Tree { OAK, MAPLE, PINE } What is the ordinal value of the MAPLE enum constant? 0 1 2 3 Tree.MAPLE

1

What happens when an individual element of an Array is passed to a method? 1.) The method does not have access to the original Array 2.) A reference to the Array is passed 3.) It is passed like any other variable 4.) All of the Above

1.) The method does not have access to the original Array.

The ________ method removes an item from an ArrayList at a specific index. 1.) pop 2.) remove 3.) clear 4.) deleteAt

2.) remove

Which is true? 1.) A program must import java.io.system to use System.out 2. ) System.output.print() only outputs objects of type String 3.) The output of println() for an object reference includes all data stored in the object 4.) Data written to System.out are placed in a buffer and eventually output

4.) Data written to System.out are placed in a buffer and eventually output

You can use the ________ method to replace an item at a specific location in an ArrayList. 1.) remove 2.) replace 3.) add 4.) set

4.) set

In addition to providing a mechanism to convert primitive data into objects, what else do the wrapper classes provide? A.) static constants B.) arrays to contain the data C.) enumerations D.) exceptions E.) None of these

A.) static constants ex. MIN_VALUE and MAX_VALUE

If you attempt to perform an operation with a null reference variable ________. A.) the program will terminate B.) Java will create an object to reference the variable C.) the resulting operation will always be zero D.) the results will be unpredictable

A.) the program will terminate

To compare two objects in a class, ________. A.) write an equals method that will make a field by field compare of the two objects B.) This cannot be done since objects consist of several fields. C.) use the == operator (for example, object1 == object2) D.) write a method to do a byte-by-byte compare of the two objects

A.) write an equals method that will make a field by field compare of the two objects

Differences between ArrayList and linked list?

An ArrayList stores items contiguously in memory. ArrayLists are advantageous because: +items can be added or removed to/from any position in the list +items are faster to access because they're stored contiguously in memory -Their major drawback is that adding/removing an item anywhere but the end of the list can cause performance issues, as larger lists might require hundreds or thousands of items to shift in order to accommodate the change in data. A linked list stores items anywhere in memory. To 'link' the list items, a memory location will hold not only the data, but also a reference to the next item in the list. +A linked list performs better while adding/removing items because fewer other items are affected. -But accessing items can be slower because the entire list has to be traversed to find the desired piece of data.

How are command-line arguments stored?

As an Array of Strings.

Define autoboxing & unboxing

Autoboxing is when a primitive data type is automatically converted to a wrapper type. (int -> Integer) Unboxing is the opposite - a wrapper class type is converted into a primitive data type. (Double -> double)

In a UML diagram for a class A.) there may be a section containing the name of the class B.) All of these C.) there may be a section containing the methods of the class D.) there may be a section containing the attributes of the class E.) classes are represented as rectangles

B.) All of these Those four attributes correctly describe a UML representation of a class.

When a method's return type is a class, what is actually returned to the calling program? A.) the values in the object that the method accessed B.) a reference to an object of that class C.) nothing - the return type is simply for documentation in this situation D.) an object of that class

B.) a reference to an object of that class

The String class's compareTo method... A.) yields true or false B.) yields 0 if the two strings are identical C.) compares two strings in a case-independent manner D.) returns 1 if the first string comes lexically before the second string E.) None of these

B.) yields 0 if the two strings are identical compareTo yields: Identical: 0 1st string comes before 2nd: -1 1st string comes after 2nd: 1

The whole-part relationship created by object aggregation is more often called a(n) ________ relationship. A.) inner class B.) extra class C.) "has a" D.) inside class

C.) "has a"

An enumerated data type can be declared inside of a method True False

FALSE

Enum constants have a toString method T F

T

How is garbage collection performed?

The JVM keeps a reference count on all reference variables. When the count on a variable reaches 0, it's considered unused (or, unreachable). Variables that go out of scope are automatically inferred as null and considered unreachable. The JVM periodically checks for unreachable variables and automatically clears them from the heap to make room for new, more relevant data.

A method defined in a class can access the class's instance data without needing to pass them as parameters. True False

True Instance data is globally available to all the class methods. They don't need to be passed. If variables of the same name as instance data are declared locally inside a method, the instance data would be hidden to the method & references would be made to the local variables instead.

A constructor may contain a return statement so long as no value (or expression) is returned. True False

True It is legal for constructors to have return statements that return nothing, but it's discouraged.

While multiple objects of the same class can exist, in a given program there can only be one version of each class. True False

True Physical instances of a class are created when an object is instantiated. There can be many objects of a String type, but only one String class.

Assume you write a program that uses the Random class but you fail to include an import statement for java.util.Random or java.util.*. What will happen when you attempt to compile and run your program? A.) The program won't run but it will compile with a warning about missing the class. B.) The program will encounter a run-time error when it attempts to access any member of the Random class. C.) The program will compile but you'll receive a warning about the missing class. D.) The program won't compile and you'll receive a syntax error about the missing class. E.) none of these

D.) The program won't compile and you'll receive a syntax error about the missing class. The program won't be able to execute because the missing class will cause undefined variables/methods in the program.

An object that refers to part of itself within its own methods can use which of the following reserved words to denote this relationship? A.) static B.) i C.) private D.) this E.) inner

D.) this 'this' is used for an object to refer to itself, or to a class as a whole. if the local var/param shares a name with global instance data, 'this' can be useful.

Java.text's NumberFormat class includes methods that: A.) allow you to format percentages B.) round their display during the formatting process C.) allow you to format currency D.) truncate their display during the formatting process E.) A, B, C, but not D

E.) A, B, C, but not D NumberFormat always rounds, not truncate.

The advantage(s) of the Random class's pseudorandom number generators, compared to the Math.random method, is(are) that A.) you can generate random ints, floats, and ints within a range B.) the generators in Random are more efficient than the one in Math.random C.) you can initialize and reinitialize Random generators D.) you may create several random number generators E.) all except B are true

E.) all except B are true Random and Math.random have the same efficiency, but all other answers are valid.

The advantages of the DecimalFormat class compared to the NumberFormat class include A.) precise control over the number of digits to be displayed B.) control over the presence of a leading zero C.) the ability to display a percent sign (%) automatically at the beginning of the display D.) the ability to truncate values rather than round them E.) only A and B

E.) only A and B Truncation is done w/ Math methods % would appear at the end, not beginning.

Static methods cannot A.) reference other objects B.) reference any data C.) invoke other static methods D.) invoke other non-static methods E.) reference non-static instance data

E.) reference non-static instance data A static method is part of the class itself, not an object. The static method is shared among all instantiated objects of the class. Because the static method is shared, it can't access non-static instance data because all non-static data are specific to instantiated objects. A static method can access static instance data bcz the instance data is shared among all objects of the class. A static method can also access parameters passed to it.


संबंधित स्टडी सेट्स

AP European History Final Study Guide

View Set

Wrist and Hand Sprains/Dislocations

View Set

Writing Equations from Word Problems

View Set

Segment 7 - Fraud & Money Laundering

View Set