CS 3330 Final || with Complete Solutions.
object correct answers software bundle of 2 related characteristics: state and behavior
- an *instance* of a class
- has a state in which all of its properties have values
fields correct answers stores *states*
methods correct answers exposes state's *behavior*
serve as primary mechanism for object-to-object communication
modularity correct answers code written and maintained independently
information-hiding correct answers details of internal implementation remain hidden from
outside world
code re-use correct answers if object already exists, you can use that object in your program
- allows specialists to implement/test/debug complex, task-specific objects to run in your own
code
Pluggability and debugging ease correct answers if object is problematic, can remove from your
app and plug in a different object as replacement
class correct answers blueprint from which individual objects are created = a template for object
- defines object properties including a valid range of values and default value
- describes object behavior
instance correct answers bicycle is an instance of the class of objects known as bicycles
EX: class Bicycle { ... }
class BicycleDemo {
main() {
// bicycle objects
Bicycle bike1 = new Bicycle();
// invoke methods
bike1.speedUp(10);
}
}
access level modifiers correct answers determine whether other classes can use a particular field
or invoke a method
,top level access modifiers correct answers 1. *public*
2. *package-private* (no explicit modifier)
member level access modifiers correct answers 1. *public*
2. *private*
3. *protected*
4. *package-private* (no explicit modifier)
public access modifier correct answers class is visible to all classes everywhere
- class
- package
- subclass
- world
protected access modifier correct answers member can only be accessed within its own package
- class
- package
- subclass
no modifier (package-private) access modifier correct answers visible only within its own
package
- class
- package
private access modifier correct answers member can only be accessed within its OWN class and
CANNOT be overridden
- class
enum types correct answers special data type that enables for a variable to be a set of predefined
constants
- in all uppercase letters
EX: MAX_WIDTH, NORTH
this keyword correct answers reference to the current object (object whose method or constructor
is being called)
- used to resolve conflicts between method parameters and instance fields/methods of the
invoked class commonly used in Java
EX:
public Point(int x, int y) {
this.x = x;
, this.y = y;
}
steps to creating an object correct answers 1. *declaration* of a new object: type and variable
name
2. *initialization*: set the values
3. *installation*: new object name and returns new address to memory location
A method in a class declared as ______ can only access ______ class members.
public, public
static, static
public, protected
static, instance
instance, static
private, public
private, private correct answers static, static
- *static method* can only access static variables
Which of the following statements is correct?
All of the statements either produce compile errors or runtime errors
Integer.parseInt(100);
Integer.parseInt(100, 16);
Integer.parseInt("12", 2);
Integer.parseInt("345", 8);
All of the statements are correct correct answers Integer.parseInt("345", 8);
parseInt(String s, int radix) OR parseInt(String s)
Which of the following statements is true?
Overloading a method is to provide more than one method with the same name but with different
signatures to distinguish them.
To override a method, the method must be defined in the subclass using the same signature and
compatible return type as in its superclass.
If a method defined in a subclass is private that has the same method signature and return type as
in its superclass which is also private, the two methods are completely unrelated.
It is a compilation error if two methods differ only in return type in the same class.
None of the answers are true
object correct answers software bundle of 2 related characteristics: state and behavior
- an *instance* of a class
- has a state in which all of its properties have values
fields correct answers stores *states*
methods correct answers exposes state's *behavior*
serve as primary mechanism for object-to-object communication
modularity correct answers code written and maintained independently
information-hiding correct answers details of internal implementation remain hidden from
outside world
code re-use correct answers if object already exists, you can use that object in your program
- allows specialists to implement/test/debug complex, task-specific objects to run in your own
code
Pluggability and debugging ease correct answers if object is problematic, can remove from your
app and plug in a different object as replacement
class correct answers blueprint from which individual objects are created = a template for object
- defines object properties including a valid range of values and default value
- describes object behavior
instance correct answers bicycle is an instance of the class of objects known as bicycles
EX: class Bicycle { ... }
class BicycleDemo {
main() {
// bicycle objects
Bicycle bike1 = new Bicycle();
// invoke methods
bike1.speedUp(10);
}
}
access level modifiers correct answers determine whether other classes can use a particular field
or invoke a method
,top level access modifiers correct answers 1. *public*
2. *package-private* (no explicit modifier)
member level access modifiers correct answers 1. *public*
2. *private*
3. *protected*
4. *package-private* (no explicit modifier)
public access modifier correct answers class is visible to all classes everywhere
- class
- package
- subclass
- world
protected access modifier correct answers member can only be accessed within its own package
- class
- package
- subclass
no modifier (package-private) access modifier correct answers visible only within its own
package
- class
- package
private access modifier correct answers member can only be accessed within its OWN class and
CANNOT be overridden
- class
enum types correct answers special data type that enables for a variable to be a set of predefined
constants
- in all uppercase letters
EX: MAX_WIDTH, NORTH
this keyword correct answers reference to the current object (object whose method or constructor
is being called)
- used to resolve conflicts between method parameters and instance fields/methods of the
invoked class commonly used in Java
EX:
public Point(int x, int y) {
this.x = x;
, this.y = y;
}
steps to creating an object correct answers 1. *declaration* of a new object: type and variable
name
2. *initialization*: set the values
3. *installation*: new object name and returns new address to memory location
A method in a class declared as ______ can only access ______ class members.
public, public
static, static
public, protected
static, instance
instance, static
private, public
private, private correct answers static, static
- *static method* can only access static variables
Which of the following statements is correct?
All of the statements either produce compile errors or runtime errors
Integer.parseInt(100);
Integer.parseInt(100, 16);
Integer.parseInt("12", 2);
Integer.parseInt("345", 8);
All of the statements are correct correct answers Integer.parseInt("345", 8);
parseInt(String s, int radix) OR parseInt(String s)
Which of the following statements is true?
Overloading a method is to provide more than one method with the same name but with different
signatures to distinguish them.
To override a method, the method must be defined in the subclass using the same signature and
compatible return type as in its superclass.
If a method defined in a subclass is private that has the same method signature and return type as
in its superclass which is also private, the two methods are completely unrelated.
It is a compilation error if two methods differ only in return type in the same class.
None of the answers are true