Java Methods and Object Relationships
12 Questions
100 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

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

a string of characters, a whole number, and a reference to an object

Java automatically stores a ________ value in all uninitialized static member variables.

0 (zero)

Static methods can only operate on ________ fields.

static

The 'has a' relationship is sometimes called a(n) ________ because one object is part of a greater whole.

<p>whole-part relationship</p> Signup and view all the answers

The key word this is the name of a reference variable that an object can use to refer to itself.

<p>True</p> Signup and view all the answers

The whole-part relationship created by object aggregation is more often called a(n) ________ relationship.

<p>'has a'</p> Signup and view all the answers

To compare two objects in a class, ________.

<p>write an equals method that will make a field by field compare of the two objects</p> Signup and view all the answers

When a field is declared static there will be ________.

<p>only one copy of the field in memory</p> Signup and view all the answers

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

<p>a reference to an object of that class</p> Signup and view all the answers

When a reference variable is passed as an argument to a method ________.

<p>the method has access to the object that the variable references</p> Signup and view all the answers

When an object is passed as an argument, it is actually a reference to the object that is passed.

<p>True</p> Signup and view all the answers

When an object reference is passed to a method, the method may change the values in the object.

<p>True</p> Signup and view all the answers

Study Notes

Java Methods and Variables

  • A Java method can return various data types including strings, whole numbers, and object references.
  • Uninitialized static member variables in Java are automatically assigned a default value of zero.
  • Static methods are restricted to operating only on static fields within a class.

Object Relationships

  • The "has a" relationship, also known as a whole-part relationship, signifies that one object is a component of another.
  • Object aggregation is frequently characterized by this whole-part relationship.

Self-Referencing and Object Comparison

  • The keyword this serves as a reference variable that allows an object to refer to itself.
  • To compare two objects, an equals method should be implemented to perform a field-by-field comparison.

Static Fields and Memory Management

  • When a field is declared as static, there is only a single copy stored in memory, regardless of how many instances of the class exist.
  • Methods whose return types are classes return references, not the objects themselves, to the calling program.

Passing References to Methods

  • When a reference variable is used as a method argument, the method gains access to the actual object referenced by that variable.
  • Passing an object as an argument corresponds to passing a reference to that object.
  • Methods that receive an object reference can modify the object's internal values.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

Explore key concepts in Java programming, focusing on methods, variables, and object relationships. Understand how static fields operate and the importance of the 'this' keyword in self-referencing objects. This quiz will enhance your knowledge of Java's unique features and memory management techniques.

More Like This

Java ArrayList Methods Quiz
10 questions
OCA C5 Mock Test Flashcards
6 questions
Use Quizgecko on...
Browser
Browser