Calling Instance Methods - AP Computer Science A
Card 1 of 30
How do you call an instance method named 'calculate' on an object 'obj'?
How do you call an instance method named 'calculate' on an object 'obj'?
Tap to reveal answer
obj.calculate();. Use dot notation: objectName.methodName();
obj.calculate();. Use dot notation: objectName.methodName();
← Didn't Know|Knew It →
What keyword is used to refer to the current object in an instance method?
What keyword is used to refer to the current object in an instance method?
Tap to reveal answer
this. References the current object instance within methods.
this. References the current object instance within methods.
← Didn't Know|Knew It →
Identify the error: 'object.method();' when 'method' requires an argument.
Identify the error: 'object.method();' when 'method' requires an argument.
Tap to reveal answer
Provide an argument: 'object.method(arg);'. Missing argument causes compile error; provide required parameter.
Provide an argument: 'object.method(arg);'. Missing argument causes compile error; provide required parameter.
← Didn't Know|Knew It →
What distinguishes an instance method from a static method?
What distinguishes an instance method from a static method?
Tap to reveal answer
Instance methods require an object to be called; static do not. Static methods belong to class; instance methods belong to objects.
Instance methods require an object to be called; static do not. Static methods belong to class; instance methods belong to objects.
← Didn't Know|Knew It →
Identify the error: 'obj.method(4, 5)' when 'method' takes no parameters.
Identify the error: 'obj.method(4, 5)' when 'method' takes no parameters.
Tap to reveal answer
Remove the arguments: 'obj.method();'. Too many arguments causes compile error; remove extras.
Remove the arguments: 'obj.method();'. Too many arguments causes compile error; remove extras.
← Didn't Know|Knew It →
What is required to call an instance method?
What is required to call an instance method?
Tap to reveal answer
An instance of the class. Instance methods must be called on specific object instances.
An instance of the class. Instance methods must be called on specific object instances.
← Didn't Know|Knew It →
What is the default return type if none is specified?
What is the default return type if none is specified?
Tap to reveal answer
There is no default; return type must be specified. Java requires explicit return type specification for all methods.
There is no default; return type must be specified. Java requires explicit return type specification for all methods.
← Didn't Know|Knew It →
How do you call the method 'add' with integer arguments 4 and 5 on 'calc'?
How do you call the method 'add' with integer arguments 4 and 5 on 'calc'?
Tap to reveal answer
calc.add(4, 5);. Pass arguments in parentheses matching parameter types.
calc.add(4, 5);. Pass arguments in parentheses matching parameter types.
← Didn't Know|Knew It →
What does 'public' signify in a method declaration?
What does 'public' signify in a method declaration?
Tap to reveal answer
The method is accessible from any other class. Highest visibility level allowing access from any class.
The method is accessible from any other class. Highest visibility level allowing access from any class.
← Didn't Know|Knew It →
What is the purpose of method overloading?
What is the purpose of method overloading?
Tap to reveal answer
To define methods with the same name but different parameters. Enables multiple method versions with different parameter signatures.
To define methods with the same name but different parameters. Enables multiple method versions with different parameter signatures.
← Didn't Know|Knew It →
Can an instance method be called without an object in Java?
Can an instance method be called without an object in Java?
Tap to reveal answer
No, it requires an object. Instance methods need object context to access instance data.
No, it requires an object. Instance methods need object context to access instance data.
← Didn't Know|Knew It →
What does 'protected' mean for a method's access level?
What does 'protected' mean for a method's access level?
Tap to reveal answer
Accessible within package and subclasses. Visible to package members and subclasses only.
Accessible within package and subclasses. Visible to package members and subclasses only.
← Didn't Know|Knew It →
How do you call method 'run' with 'speed' argument on object 'vehicle'?
How do you call method 'run' with 'speed' argument on object 'vehicle'?
Tap to reveal answer
vehicle.run(speed);. Argument passes data to method parameter.
vehicle.run(speed);. Argument passes data to method parameter.
← Didn't Know|Knew It →
What is the effect of calling a method with no return statement?
What is the effect of calling a method with no return statement?
Tap to reveal answer
If non-void, causes a compile-time error. Non-void methods must return value; missing return fails compilation.
If non-void, causes a compile-time error. Non-void methods must return value; missing return fails compilation.
← Didn't Know|Knew It →
What is an overloaded method?
What is an overloaded method?
Tap to reveal answer
A method with the same name but different parameters. Same name but different parameter list creates overload.
A method with the same name but different parameters. Same name but different parameter list creates overload.
← Didn't Know|Knew It →
How do you refer to the current class's method from another method?
How do you refer to the current class's method from another method?
Tap to reveal answer
Use 'this.methodName()'. Optional 'this.' prefix clarifies current object method call.
Use 'this.methodName()'. Optional 'this.' prefix clarifies current object method call.
← Didn't Know|Knew It →
What must match when calling an instance method with arguments?
What must match when calling an instance method with arguments?
Tap to reveal answer
The number, type, and order of parameters. Method signature must exactly match call arguments.
The number, type, and order of parameters. Method signature must exactly match call arguments.
← Didn't Know|Knew It →
How do you call a method 'update' on 'obj' with 'newValue'?
How do you call a method 'update' on 'obj' with 'newValue'?
Tap to reveal answer
obj.update(newValue);. Standard method call with single argument parameter.
obj.update(newValue);. Standard method call with single argument parameter.
← Didn't Know|Knew It →
Can 'this' keyword be used in static methods?
Can 'this' keyword be used in static methods?
Tap to reveal answer
No, 'this' is not available in static methods. 'this' refers to instance; static methods have no instance.
No, 'this' is not available in static methods. 'this' refers to instance; static methods have no instance.
← Didn't Know|Knew It →
What does 'return' do in a method?
What does 'return' do in a method?
Tap to reveal answer
Exits the method and optionally returns a value. Terminates method execution and sends result to caller.
Exits the method and optionally returns a value. Terminates method execution and sends result to caller.
← Didn't Know|Knew It →
What is the access level of a method if no modifier is provided?
What is the access level of a method if no modifier is provided?
Tap to reveal answer
Package-private (default). No modifier means package-private visibility within same package.
Package-private (default). No modifier means package-private visibility within same package.
← Didn't Know|Knew It →
How do you call method 'display' with 'message' on object 'screen'?
How do you call method 'display' with 'message' on object 'screen'?
Tap to reveal answer
screen.display(message);. Passes string argument to display method parameter.
screen.display(message);. Passes string argument to display method parameter.
← Didn't Know|Knew It →
What does overloading a method allow?
What does overloading a method allow?
Tap to reveal answer
Multiple methods with the same name but different parameters. Provides multiple method implementations for different parameter types.
Multiple methods with the same name but different parameters. Provides multiple method implementations for different parameter types.
← Didn't Know|Knew It →
Why must a void method not have a return statement with a value?
Why must a void method not have a return statement with a value?
Tap to reveal answer
It causes a compile-time error. Void methods cannot return values; only execution control.
It causes a compile-time error. Void methods cannot return values; only execution control.
← Didn't Know|Knew It →
When is an instance method appropriate over a static method?
When is an instance method appropriate over a static method?
Tap to reveal answer
When the method needs to access instance fields. Instance methods can access and modify object state.
When the method needs to access instance fields. Instance methods can access and modify object state.
← Didn't Know|Knew It →
What is the correct way to call a method 'compute' on instance 'obj'?
What is the correct way to call a method 'compute' on instance 'obj'?
Tap to reveal answer
obj.compute();. Standard dot notation for calling methods on objects.
obj.compute();. Standard dot notation for calling methods on objects.
← Didn't Know|Knew It →
Identify the error: 'obj.method(1, 2)' when 'method' is protected.
Identify the error: 'obj.method(1, 2)' when 'method' is protected.
Tap to reveal answer
Cannot access from outside package or subclass. Protected access requires package membership or inheritance relationship.
Cannot access from outside package or subclass. Protected access requires package membership or inheritance relationship.
← Didn't Know|Knew It →
What happens if a method's return type is void and it returns a value?
What happens if a method's return type is void and it returns a value?
Tap to reveal answer
A compile-time error occurs. Void methods cannot return values; causes compilation failure.
A compile-time error occurs. Void methods cannot return values; causes compilation failure.
← Didn't Know|Knew It →
What is required for method overloading?
What is required for method overloading?
Tap to reveal answer
Different parameter lists. Overloading requires distinct parameter signatures for each version.
Different parameter lists. Overloading requires distinct parameter signatures for each version.
← Didn't Know|Knew It →
What is method chaining?
What is method chaining?
Tap to reveal answer
Calling multiple methods on the same object in a single statement. Links method calls together for fluent programming style.
Calling multiple methods on the same object in a single statement. Links method calls together for fluent programming style.
← Didn't Know|Knew It →