AP Computer Science a Flashcards: Methods Passing And Returning References

Study Methods Passing And Returning References in AP Computer Science a with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science a

Methods Passing And Returning References

0 mastered0 still learning

0% Complete

QUESTION
1/ 71

Which keyword is necessary to return an object from a method?

Tap card or press Space to flip

ANSWER

return. Required for all method returns.

How well did you know it?

Card 1 / 71

What this deck covers

This deck focuses on Methods Passing And Returning References, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science a.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: Which keyword is necessary to return an object from a method?

Answer: return. Required for all method returns.

Flashcard 2: What will 'return null;' do in a method returning a reference?

Answer: Returns no object, just null. Explicitly returns no object reference.

Flashcard 3: What occurs if a method returns null by default?

Answer: No object is returned; it represents nothing. Null indicates no object reference exists.

Flashcard 4: What is the result of passing an object to a method by reference?

Answer: The method can modify the object's fields. Reference passing enables object modification.

Flashcard 5: How do you define a method that accepts an object as an argument?

Answer: Use the object's class as parameter type. Parameter type must match the object's class.

Flashcard 6: Identify the correct method signature for returning a MyClass object.

Answer: public MyClass methodName(). Return type matches the class name.

Flashcard 7: How do you return an object reference from a method?

Answer: Use the 'return' keyword followed by the object. Return statement sends object reference back.

Flashcard 8: What is the consequence of returning a null reference from a method?

Answer: It signifies no object is being returned. Null means no valid object reference.

Flashcard 9: What is the outcome of passing a null reference to a method?

Answer: NullPointerException if dereferenced. Accessing null reference throws runtime exception.

Flashcard 10: State the method signature for a method returning an object of class MyClass.

Answer: public MyClass methodName(). Method signature shows return type and parameters.

Flashcard 11: What is the effect of returning 'this' in a method?

Answer: Returns the current instance of the class. Enables method chaining and self-reference.

Flashcard 12: What is the syntax to pass an object as a parameter in a method?

Answer: methodName(ObjectType objectName). Parameter syntax includes type and variable name.

Flashcard 13: What is the result of passing an object to a method by reference?

Answer: The method can modify the object's fields. Reference passing enables object modification.

Flashcard 14: When is a new object created during method execution?

Answer: When using 'new' keyword inside the method. Constructor calls create new object instances.

Flashcard 15: What type of method can return an object reference in Java?

Answer: Any method with a non-void return type. Non-void methods can return object references.

Flashcard 16: What will 'return this;' do in a method of a class?

Answer: Returns the current object reference. 'this' refers to the current object instance.

Flashcard 17: Which keyword is necessary to return an object from a method?

Answer: return. Required for all method returns.

Flashcard 18: What is the outcome if you pass a null object to a method?

Answer: Risk of NullPointerException if dereferenced. Null references cause exceptions when used.

Flashcard 19: How do you indicate a method returns no object?

Answer: Use 'void' as the method's return type. Void indicates no return value expected.

Flashcard 20: What is the default return value of a method that returns an object?

Answer: null. Methods return null when no object is provided.

Flashcard 21: What will 'return this;' do in a method of a class?

Answer: Returns the current object reference. 'this' refers to the current object instance.

Flashcard 22: Which statement correctly passes an object to a method?

Answer: methodName(object);. Object name without parentheses passes reference.

Flashcard 23: Which option correctly returns an object of type String?

Answer: return "Example";. String literals return String object references.

Flashcard 24: Identify the error: 'public String getName() { return name }'

Answer: Missing semicolon after 'name'. Missing semicolon terminates return statement.

Flashcard 25: What does 'return null;' indicate in a method returning an object?

Answer: No object is being returned. Explicit way to return no object.

Flashcard 26: Which statement correctly returns an object created within a method?

Answer: return new ObjectType();. Constructor creates and returns new object.

Flashcard 27: What is the syntax to pass an object as a parameter in a method?

Answer: methodName(ObjectType objectName). Parameter syntax includes type and variable name.

Flashcard 28: Identify the correct method signature for returning a MyClass object.

Answer: public MyClass methodName(). Return type matches the class name.

Flashcard 29: Which statement correctly passes an object to a method?

Answer: methodName(object);. Object name without parentheses passes reference.

Flashcard 30: Find and correct the error: 'return objectName()' for returning an object.

Answer: Correct: 'return objectName;'. Parentheses invoke method; remove for variable return.

Flashcard 31: How do you handle a null return value from a method?

Answer: Check for null before using the return value. Prevents NullPointerException when accessing.

Flashcard 32: What happens if you modify an object's field inside a method?

Answer: The modification persists outside the method. Object state changes persist after method ends.

Flashcard 33: What is the effect of modifying an object within a method?

Answer: Changes persist outside the method. Reference passing means original object is modified.

Flashcard 34: State the method signature for a method returning an object of class MyClass.

Answer: public MyClass methodName(). Method signature shows return type and parameters.

Flashcard 35: What is the outcome of passing a null reference to a method?

Answer: NullPointerException if dereferenced. Accessing null reference throws runtime exception.

Flashcard 36: Identify the result of modifying a primitive data type passed to a method.

Answer: Modification does not persist outside. Primitives are passed by value, not reference.

Flashcard 37: Which statement correctly returns an object created within a method?

Answer: return new ObjectType();. Constructor creates and returns new object.

Flashcard 38: What happens when you pass a reference of an object to a method?

Answer: The method can modify the object's state. Reference allows access to the original object.

Flashcard 39: Identify the error: 'public void method() { return new MyClass(); }'

Answer: Error: method has void return type. Void methods cannot return any value.

Flashcard 40: What will 'return null;' do in a method returning a reference?

Answer: Returns no object, just null. Explicitly returns no object reference.

Flashcard 41: Identify the result of modifying a primitive data type passed to a method.

Answer: Modification does not persist outside. Primitives are passed by value, not reference.

Flashcard 42: Find and correct the error: 'return objectName()' for returning an object.

Answer: Correct: 'return objectName;'. Parentheses invoke method; remove for variable return.

Flashcard 43: Which option correctly returns an object of type String?

Answer: return "Example";. String literals return String object references.

Flashcard 44: When passing an object to a method, what is actually passed?

Answer: The reference to the object. Memory address, not the entire object.

Flashcard 45: When passing an object to a method, what is actually passed?

Answer: The reference to the object. Memory address, not the entire object.

Flashcard 46: How do you return an object reference from a method?

Answer: Use the 'return' keyword followed by the object. Return statement sends object reference back.

Flashcard 47: What does 'null' signify when returned by a method?

Answer: The method does not return an actual object. Null represents absence of an object reference.

Flashcard 48: How do you define a method that accepts an object as an argument?

Answer: Use the object's class as parameter type. Parameter type must match the object's class.

Flashcard 49: What is the default return value of a method that returns an object?

Answer: null. Methods return null when no object is provided.

Flashcard 50: When is a new object created during method execution?

Answer: When using 'new' keyword inside the method. Constructor calls create new object instances.

Flashcard 51: What does 'return null;' indicate in a method returning an object?

Answer: No object is being returned. Explicit way to return no object.

Flashcard 52: Identify the error: 'public void method() { return new MyClass(); }'

Answer: Error: method has void return type. Void methods cannot return any value.

Flashcard 53: What does it mean to pass an object reference in Java?

Answer: Passing the memory address of the object. Objects are passed by reference, not value.

Flashcard 54: What type of method can return an object reference in Java?

Answer: Any method with a non-void return type. Non-void methods can return object references.

Flashcard 55: What must match when a method returns an object?

Answer: The return type and the object's type. Type compatibility ensures valid returns.

Flashcard 56: What is the consequence of returning a null reference from a method?

Answer: It signifies no object is being returned. Null means no valid object reference.

Flashcard 57: What happens if you modify an object's field inside a method?

Answer: The modification persists outside the method. Object state changes persist after method ends.

Flashcard 58: Identify the error: 'public String getName() { return name }'

Answer: Missing semicolon after 'name'. Missing semicolon terminates return statement.

Flashcard 59: What must match when a method returns an object?

Answer: The return type and the object's type. Type compatibility ensures valid returns.

Flashcard 60: Identify the keyword used to return an object reference from a method.

Answer: return. Basic keyword for returning any value or reference.

Flashcard 61: What is the effect of returning 'this' in a method?

Answer: Returns the current instance of the class. Enables method chaining and self-reference.

Flashcard 62: What does 'null' signify when returned by a method?

Answer: The method does not return an actual object. Null represents absence of an object reference.

Flashcard 63: Identify the keyword used to return an object reference from a method.

Answer: return. Basic keyword for returning any value or reference.

Flashcard 64: What should a method return if it is declared to return an object?

Answer: An object or a reference to an object. Return type determines what can be returned.

Flashcard 65: How do you handle a null return value from a method?

Answer: Check for null before using the return value. Prevents NullPointerException when accessing.

Flashcard 66: What occurs if a method returns null by default?

Answer: No object is returned; it represents nothing. Null indicates no object reference exists.

Flashcard 67: What is the outcome if you pass a null object to a method?

Answer: Risk of NullPointerException if dereferenced. Null references cause exceptions when used.

Flashcard 68: What is the effect of modifying an object within a method?

Answer: Changes persist outside the method. Reference passing means original object is modified.

Flashcard 69: How do you indicate a method returns no object?

Answer: Use 'void' as the method's return type. Void indicates no return value expected.

Flashcard 70: What happens when you pass a reference of an object to a method?

Answer: The method can modify the object's state. Reference allows access to the original object.

Flashcard 71: What should a method return if it is declared to return an object?

Answer: An object or a reference to an object. Return type determines what can be returned.