Chapter 3: A First Look at Classes and Objects

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

To find the classes needed for an objective -oriented application, you identify all the verbs in a description of the problem domain

False

When passing multiple times, the order in which the are passed is not important

False

public class Student { private String name; private double gpa; public Student (String newName, double newGPA) { name = newName; gpa = newGPA; } public String getName( ) { return name; } } Which of the following could be used in the StudentTester class to print the name associated with the Student object instantiated in problem 3?

System.out.println(sam.getName( ));

Consider the following code segment. Student s1 = new Student ("Emma Garcia", 3.9); Student s2 = new Student ("Alice Whitman", 3.2); s2 = s1; s2.setGpa (4.0); System.out.println (s1.getGpa( )); What is printed as a result of executing the code segment?

4.0

If you do not want to write a constructor for a class, this is automatically provided for the class

default constructor

What is a parameter variable?

describes attributes or fields

What is a constructor's return type?

doesn't have one

This is a member of class that holds data

field

An object is a

instance

This is a method that stores a value in a field or in some other way changes the value of a field

mutator

The keyword causes an object to be created in memory

new

How do you identify the potential classes in a problem domain description?

nouns

How many public classes can be in one file?

one

What are the 3 Java access modifiers?

public, private, protected

When a local variable has the same name as a field, the local variable's name does what to the fields name

shadows

What must be true about the file name and the public class name(s)?

they must match

What does UML stand for?

unified modeling language

What method is used to find the size of a String object?

.length();

A class's responsibility are

1. Things the class knows 2. Action the class performs

The relationship between a class and an object can be described as:

A class is the blueprint for an object and objects are instantiated from it.

When you write a constructor for a class, it still has the default constructor that java automatically provides

False

Which of the following is a valid constructor declaration for the Cube class? public static Cube( ) public void Cube( ) public Cube( ) public Cube(int side)

III and IV only

public class Student { private String name; private double gpa; public Student (String newName, double newGPA) { name = newName; gpa = newGPA; } public String getName( ) { return name; } } Which of the following could be used to instantiate a new Student object called sam?

Student sam = new Student ("Sam Smith", 3.5)

Each instance of a class has its own set of instance fields

True

The occurrence of a string literal in a java program causes a string to object to be created in a memory, initialized with a string literal

True

When passing an argument to a method, the arguments's data type must be compatible with the parameters variable type

True

This is a method that gets a value from class field, but does not change it

accessor

A collection of programming statements that specify the attributes and methods a particular type of object can have is

class

What are the 3 components of a UML diagram?

class, attributes, methods

This is a method automatically called when an instance of a class is created

constructor

A class is Analogous to a

cookie cutter

public class Student { private String name; private double gpa; public Student (String newName, double newGPA) { name = newName; gpa = newGPA; } public String getName( ) { return name; } } Which of the following is the correct way to write a method that changes the value of a Student object's gpa variable?

public void setGpa (double newGpa) { gpa=newGpa; }

The key word causes a value to be sent back from a method to the statement that called it

return

When the value of an item is dependent on other data, and then item is not updated when the other data is changed, what has the value become

stale

A string literal, such as "Joe", causes what type of object to be created?

string


Kaugnay na mga set ng pag-aaral

Unit 8 Questions (COMFORT PAIN, SLEEP, MOBILITY, SAFETY, CARING INTERVENTION)

View Set

AP Environmental Chapter 5/6 Review Questions

View Set

FINAL EXAM INTERNATIONAL MARKETING

View Set

Bios 242 Week 1 Concepts: The Cell

View Set