CSC 118 Chapter 8

Ace your homework & exams now with Quizwiz!

If ClassA extends ClassB, then

public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA

An object's ________ is simply the data that is stored in the object's fields at any given moment.

state

A static field is created by placing:

the key word static after the access specifier and before the field's data type

When a reference variable is passed as an argument to a method:

the method has access to the object that the variable references

If you attempt to perform an operation with a null reference variable

the program will terminate

If a superclass does not have a default constructor or a no-arg constructor:

then a class that inherits from it, must call one of the constructors that the superclass does have.

If object1 and object2 are objects of the same class, to make object2 a copy of object1:

write a copy method that will make a field by field copy of object1 data members into object2 data members

To compare two objects in a class:

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

If a subclass constructor does not explicitly call a superclass constructor:

Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes

What will be returned from a method, if the following is the method header? public Rectangle getRectangle()

The address of an object of the class Rectangle

If str is declared as: String str = "ABCDEFGHI"; What will be returned from Character.toLowerCase(str.charAt(3))?

d

A declaration for an enumerated type begins with this key word.

enum

If a random access file contains a stream of characters, which of the following would you use to set the pointer on the fifth character?

file.seek(8);

An exception's default error message can be retrieved using this method

getMessage()

A deep copy of an object:

is an operation that copies an aggregate object is an operation that copies an object, and all the objects it references

A static field is created by placing:

The key word static after the access specifier and before the field's data type

All exceptions are instances of classes that extend this class.

Throwable

Look at the following declaration: enum Tree { OAK, MAPLE, PINE } What is the fully-qualified name of the PINE enum constant?

Tree.PINE

To convert the string, str = "285" to an int, use the following statement:

int x = Integer.parseInt(str);

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

1

For the following code, how many times would the for loop execute? String str = "a.b.c.d.e.f"; String[] tockens = str.split("."); for (String s : tokens) System.out.println(s);

6

When a method's return type is a class, what is actually returned to the calling program?

A reference to an object of that class

If a method doesn't handle a possible checked exception, what must the method have?

A throws clause in its header

In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC

ClassA

In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC

ClassB

To read data from a binary file you create objects from the following classes:

FileInputStream and DataInputStream

If you want to append data to the existing binary file, BinaryFile.dat, use the following statements to open the file.

FileOutputStream fstream = new FIleOutputStream("BinaryFile.dat", true); DataPutput Stream binaryOutFile = new DataOutputStream(fstream);

Assuming the following declaration exists: enum Tree { OAK, MAPLE, PINE } What will the following code display? System.out.println(Tree.OAK);

OAK

In order for an object to be serialized, its class must implement this interface.

Serializable

Static methods can only operate on ________ fields.

Static

In an inheritance relationship:

The superclass constructor always executes before the subclass constructor

If the following is from the method section of a UML diagram, which of the following statements is TRUE? + add(object2:Stock): Stock

This is a public method named add that accepts and returns references to objects in the Stock class.

If the following is from the method section of a UML diagram, which of the following statements is TRUE? + equals(object2:Stock) : boolean

This is a public method that accepts a Stock object as its argument and returns a boolean value.

All exceptions are instances of classes that extend this class

Throwable

In UML diagrams, inheritance is shown:

With a line that has an open arrowhead at one end that points to the superclass

You cannot use the fully-qualified name of an enum constant for this.

a case expression

In Java, it is possible to write a method that will return:

a whole number a monetary value a string of characters a reference to an object

If you have defined a class named SavingsAccount with a public static data member named numberOfAccounts, and created a SavingsAccount object in main referenced by the variable account20, which of the following will assign numberOfAccounts to numAccounts in main (numAccounts is declared in main as well)?

numAccounts = SavingsAccount.numberOfAccounts; None of these, you cannot reference a static data member.

You cannot use the == operator to compare the contents of:

objects

If two methods have the same name but different signatures, they are:

overloaded

A subclass may call an overridden superclass method by:

prefixing its name with the super key word and a dot (.)


Related study sets

Business Software Applications Chapter 20

View Set

Chapter 33 Complementary & Alternative Therapies

View Set

Ch. 6, GEOL 100 Exam #3 Review (Chps. 6, 9, 10, and 11)

View Set