AP Computer Science a Flashcards: Calling Instance Methods

Study Calling Instance Methods 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

Calling Instance Methods

0 mastered0 still learning

0% Complete

QUESTION
1/ 80

What keyword is used to refer to the current object in an instance method?

Tap card or press Space to flip

ANSWER

this. References the current object instance within methods.

How well did you know it?

Card 1 / 80

What this deck covers

This deck focuses on Calling Instance Methods, 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: What keyword is used to refer to the current object in an instance method?

Answer: this. References the current object instance within methods.

Flashcard 2: What is an instance method in Java?

Answer: A method that operates on an instance of a class. Operates on specific object instances and can access instance variables.

Flashcard 3: What is the access level of a method if no modifier is provided?

Answer: Package-private (default). No modifier means package-private visibility within same package.

Flashcard 4: What happens if a method is called with incorrect argument types?

Answer: A compile-time error occurs. Type mismatch prevents compilation; arguments must match parameters.

Flashcard 5: What does the return type 'void' signify in a method declaration?

Answer: The method does not return a value. Method completes without returning any data to caller.

Flashcard 6: What is the correct way to call a method 'compute' on instance 'obj'?

Answer: obj.compute();. Standard dot notation for calling methods on objects.

Flashcard 7: What is required for method overloading?

Answer: Different parameter lists. Overloading requires distinct parameter signatures for each version.

Flashcard 8: What does 'public' signify in a method declaration?

Answer: The method is accessible from any other class. Highest visibility level allowing access from any class.

Flashcard 9: What is an overloaded method?

Answer: A method with the same name but different parameters. Same name but different parameter list creates overload.

Flashcard 10: What happens if a method's return type is void and it returns a value?

Answer: A compile-time error occurs. Void methods cannot return values; causes compilation failure.

Flashcard 11: Identify the error: 'obj.method(1, 2)' when 'method' is protected.

Answer: Cannot access from outside package or subclass. Protected access requires package membership or inheritance relationship.

Flashcard 12: How do you call a method 'update' on 'obj' with 'newValue'?

Answer: obj.update(newValue);. Standard method call with single argument parameter.

Flashcard 13: Can an instance method be called without an object in Java?

Answer: No, it requires an object. Instance methods need object context to access instance data.

Flashcard 14: Identify the error: 'object.method();' when 'method' requires an argument.

Answer: Provide an argument: 'object.method(arg);'. Missing argument causes compile error; provide required parameter.

Flashcard 15: Can 'this' keyword be used in static methods?

Answer: No, 'this' is not available in static methods. 'this' refers to instance; static methods have no instance.

Flashcard 16: What does 'return' do in a method?

Answer: Exits the method and optionally returns a value. Terminates method execution and sends result to caller.

Flashcard 17: Identify the return type: 'public int getValue() { return x; }'

Answer: int. Return type appears before method name in declaration.

Flashcard 18: When is an instance method appropriate over a static method?

Answer: When the method needs to access instance fields. Instance methods can access and modify object state.

Flashcard 19: How do you call the method 'add' with integer arguments 4 and 5 on 'calc'?

Answer: calc.add(4, 5);. Pass arguments in parentheses matching parameter types.

Flashcard 20: Identify the error: 'obj.method(1, 2)' when 'method' is protected.

Answer: Cannot access from outside package or subclass. Protected access requires package membership or inheritance relationship.

Flashcard 21: What is the default return type if none is specified?

Answer: There is no default; return type must be specified. Java requires explicit return type specification for all methods.

Flashcard 22: What must match when calling an instance method with arguments?

Answer: The number, type, and order of parameters. Method signature must exactly match call arguments.

Flashcard 23: What is required to call an instance method?

Answer: An instance of the class. Instance methods must be called on specific object instances.

Flashcard 24: When is the 'this' keyword used?

Answer: To refer to the current instance of a class. Disambiguates between instance variables and parameters with same name.

Flashcard 25: What does 'protected' mean for a method's access level?

Answer: Accessible within package and subclasses. Visible to package members and subclasses only.

Flashcard 26: How do you call an instance method named 'calculate' on an object 'obj'?

Answer: obj.calculate();. Use dot notation: objectName.methodName();

Flashcard 27: Identify the error: 'obj.method(4, 5)' when 'method' takes no parameters.

Answer: Remove the arguments: 'obj.method();'. Too many arguments causes compile error; remove extras.

Flashcard 28: What is the access level of a method if no modifier is provided?

Answer: Package-private (default). No modifier means package-private visibility within same package.

Flashcard 29: What does the return type 'void' signify in a method declaration?

Answer: The method does not return a value. Method completes without returning any data to caller.

Flashcard 30: What distinguishes an instance method from a static method?

Answer: Instance methods require an object to be called; static do not. Static methods belong to class; instance methods belong to objects.

Flashcard 31: What is an overloaded method?

Answer: A method with the same name but different parameters. Same name but different parameter list creates overload.

Flashcard 32: What is method chaining?

Answer: Calling multiple methods on the same object in a single statement. Links method calls together for fluent programming style.

Flashcard 33: Can 'this' keyword be used in static methods?

Answer: No, 'this' is not available in static methods. 'this' refers to instance; static methods have no instance.

Flashcard 34: Why must a void method not have a return statement with a value?

Answer: It causes a compile-time error. Void methods cannot return values; only execution control.

Flashcard 35: Identify the error: 'object.method();' when 'method' requires an argument.

Answer: Provide an argument: 'object.method(arg);'. Missing argument causes compile error; provide required parameter.

Flashcard 36: How do you call a method 'print' with no arguments on 'printer'?

Answer: printer.print();. Empty parentheses indicate no parameters required.

Flashcard 37: What must match when calling an instance method with arguments?

Answer: The number, type, and order of parameters. Method signature must exactly match call arguments.

Flashcard 38: How do you call method 'run' with 'speed' argument on object 'vehicle'?

Answer: vehicle.run(speed);. Argument passes data to method parameter.

Flashcard 39: What is required for method overloading?

Answer: Different parameter lists. Overloading requires distinct parameter signatures for each version.

Flashcard 40: What does overloading a method allow?

Answer: Multiple methods with the same name but different parameters. Provides multiple method implementations for different parameter types.

Flashcard 41: Can an instance method be called without an object in Java?

Answer: No, it requires an object. Instance methods need object context to access instance data.

Flashcard 42: How do you call a method 'print' with no arguments on 'printer'?

Answer: printer.print();. Empty parentheses indicate no parameters required.

Flashcard 43: What is the default return type if none is specified?

Answer: There is no default; return type must be specified. Java requires explicit return type specification for all methods.

Flashcard 44: How do you call a method 'display' of class 'Screen' on an instance 'screenObj'?

Answer: screenObj.display();. Standard object.method() syntax for instance method calls.

Flashcard 45: What is the syntax to define an instance method in Java?

Answer: accessModifier returnType methodName(parameters) { body }. Standard format for declaring methods with optional parameters.

Flashcard 46: How do you call a method 'update' on 'obj' with 'newValue'?

Answer: obj.update(newValue);. Standard method call with single argument parameter.

Flashcard 47: What is the purpose of method overloading?

Answer: To define methods with the same name but different parameters. Enables multiple method versions with different parameter signatures.

Flashcard 48: What is method chaining?

Answer: Calling multiple methods on the same object in a single statement. Links method calls together for fluent programming style.

Flashcard 49: How do you call method 'display' with 'message' on object 'screen'?

Answer: screen.display(message);. Passes string argument to display method parameter.

Flashcard 50: How do you refer to the current class's method from another method?

Answer: Use 'this.methodName()'. Optional 'this.' prefix clarifies current object method call.

Flashcard 51: How do you call an instance method named 'calculate' on an object 'obj'?

Answer: obj.calculate();. Use dot notation: objectName.methodName();

Flashcard 52: What distinguishes an instance method from a static method?

Answer: Instance methods require an object to be called; static do not. Static methods belong to class; instance methods belong to objects.

Flashcard 53: When is an instance method appropriate over a static method?

Answer: When the method needs to access instance fields. Instance methods can access and modify object state.

Flashcard 54: What is the effect of calling a method with no return statement?

Answer: If non-void, causes a compile-time error. Non-void methods must return value; missing return fails compilation.

Flashcard 55: What is the syntax to define an instance method in Java?

Answer: accessModifier returnType methodName(parameters) { body }. Standard format for declaring methods with optional parameters.

Flashcard 56: What happens if a method is called with incorrect argument types?

Answer: A compile-time error occurs. Type mismatch prevents compilation; arguments must match parameters.

Flashcard 57: What is the purpose of method overloading?

Answer: To define methods with the same name but different parameters. Enables multiple method versions with different parameter signatures.

Flashcard 58: What keyword is used to refer to the current object in an instance method?

Answer: this. References the current object instance within methods.

Flashcard 59: Identify the error in 'obj.calculate()' when 'calculate' is private.

Answer: Cannot access private method from outside class. Private methods only accessible within same class.

Flashcard 60: What does overloading a method allow?

Answer: Multiple methods with the same name but different parameters. Provides multiple method implementations for different parameter types.

Flashcard 61: What does 'public' signify in a method declaration?

Answer: The method is accessible from any other class. Highest visibility level allowing access from any class.

Flashcard 62: Identify the error: 'obj.method(4, 5)' when 'method' takes no parameters.

Answer: Remove the arguments: 'obj.method();'. Too many arguments causes compile error; remove extras.

Flashcard 63: How do you call method 'display' with 'message' on object 'screen'?

Answer: screen.display(message);. Passes string argument to display method parameter.

Flashcard 64: Identify the return type: 'public int getValue() { return x; }'

Answer: int. Return type appears before method name in declaration.

Flashcard 65: When is the 'this' keyword used?

Answer: To refer to the current instance of a class. Disambiguates between instance variables and parameters with same name.

Flashcard 66: How do you call method 'run' with 'speed' argument on object 'vehicle'?

Answer: vehicle.run(speed);. Argument passes data to method parameter.

Flashcard 67: How do you refer to the current class's method from another method?

Answer: Use 'this.methodName()'. Optional 'this.' prefix clarifies current object method call.

Flashcard 68: What is required to call an instance method?

Answer: An instance of the class. Instance methods must be called on specific object instances.

Flashcard 69: How do you call the method 'add' with integer arguments 4 and 5 on 'calc'?

Answer: calc.add(4, 5);. Pass arguments in parentheses matching parameter types.

Flashcard 70: Why must a void method not have a return statement with a value?

Answer: It causes a compile-time error. Void methods cannot return values; only execution control.

Flashcard 71: How do you call a method 'display' of class 'Screen' on an instance 'screenObj'?

Answer: screenObj.display();. Standard object.method() syntax for instance method calls.

Flashcard 72: What is the effect of calling a method with no return statement?

Answer: If non-void, causes a compile-time error. Non-void methods must return value; missing return fails compilation.

Flashcard 73: What happens if a method's return type is void and it returns a value?

Answer: A compile-time error occurs. Void methods cannot return values; causes compilation failure.

Flashcard 74: Identify the error in 'obj.calculate()' when 'calculate' is private.

Answer: Cannot access private method from outside class. Private methods only accessible within same class.

Flashcard 75: What is the role of parameters in an instance method?

Answer: They allow input to be passed to the method. Parameters accept data from caller for method processing.

Flashcard 76: What is the role of parameters in an instance method?

Answer: They allow input to be passed to the method. Parameters accept data from caller for method processing.

Flashcard 77: What does 'protected' mean for a method's access level?

Answer: Accessible within package and subclasses. Visible to package members and subclasses only.

Flashcard 78: What does 'return' do in a method?

Answer: Exits the method and optionally returns a value. Terminates method execution and sends result to caller.

Flashcard 79: What is the correct way to call a method 'compute' on instance 'obj'?

Answer: obj.compute();. Standard dot notation for calling methods on objects.

Flashcard 80: What is an instance method in Java?

Answer: A method that operates on an instance of a class. Operates on specific object instances and can access instance variables.