CompSci.rocks

APIs, Comments, and Method Signatures

Free AP Computer Science A multiple-choice practice for topics 1.7–1.9, Unit 1 (Using Objects and Methods). Answer five random questions, check your work, and review the essential knowledge behind each one.

Unit 1: Using Objects and Methods. Topics 1.7–1.9. This set has 55 questions. Each time the page loads you get five of them, chosen at random. Pick an answer, press Check answer, and read the explanation for every choice. Reload the page or use New questions for a fresh five.

Topics assessed

  • 1.7 Application Program Interface (API) and Libraries
  • 1.8 Documentation with Comments
  • 1.9 Method Signatures

Practice questions

Loading questions…

Essential knowledge for this set

These are the essential knowledge (EKS) statements from the AP Computer Science A Course and Exam Description that the 55 questions in this set assess, grouped by topic and learning objective. The table under each question links here.

Topic 1.7: Application Program Interface (API) and Libraries

1.7.A — Identify the attributes and behaviors of a class found in the libraries contained in an API.

  • 1.7.A.1 Libraries are collections of classes. An application programming interface (API) specification informs the programmer how to use those classes. Documentation found in API specifications and libraries is essential to understanding the attributes and behaviors of a class defined by the API. A class defines a specific reference type. Classes in the APIs and libraries are grouped into packages. Existing classes and class libraries can be utilized to create objects.
  • 1.7.A.2 Attributes refer to the data related to the class and are stored in variables. Behaviors refer to what instances of the class can do (or what can be done with them) and are defined by methods.

Topic 1.8: Documentation with Comments

1.8.A — Describe the functionality and use of code through comments.

  • 1.8.A.1 Comments are written for both the original programmer and other programmers to understand the code and its functionality, but are ignored by the compiler and are not executed when the program is run. Three types of comments in Java include /* */, which generates a block of comments; //, which generates a comment on one line; and /** */, which are Javadoc comments and are used to create API documentation.
  • 1.8.A.2 A precondition is a condition that must be true just prior to the execution of a method in order for it to behave as expected. There is no expectation that the method will check to ensure preconditions are satisfied.
  • 1.8.A.3 A postcondition is a condition that must always be true after the execution of a method. Postconditions describe the outcome of the execution in terms of what is being returned or the current value of the attributes of an object.

Topic 1.9: Method Signatures

1.9.A — Identify the correct method to call based on documentation and method signatures.

  • 1.9.A.1 A method is a named block of code that only runs when it is called. A block of code is any section of code that is enclosed in braces. Procedural abstraction allows a programmer to use a method by knowing what the method does even if they do not know how the method was written.
  • 1.9.A.2 A parameter is a variable declared in the header of a method or constructor and can be used inside the body of the method. This allows values or arguments to be passed and used by a method or constructor. A method signature for a method with parameters consists of the method name and the ordered list of parameter types. A method signature for a method without parameters consists of the method name and an empty parameter list.

1.9.B — Describe how to call methods.

  • 1.9.B.1 A void method does not have a return value and is therefore not called as part of an expression.
  • 1.9.B.2 A non-void method returns a value that is the same type as the return type in the header. To use the return value when calling a non-void method, it must be stored in a variable or used as part of an expression.
  • 1.9.B.3 An argument is a value that is passed into a method when the method is called. The arguments passed to a method must be compatible in number and order with the types identified in the parameter list of the method signature. When calling methods, arguments are passed using call by value. Call by value initializes the parameters with copies of the arguments.
  • 1.9.B.4 Methods are said to be overloaded when there are multiple methods with the same name but different signatures.
  • 1.9.B.5 A method call interrupts the sequential execution of statements, causing the program to first execute the statements in the method before continuing. Once the last statement in the method has been executed or a return statement is executed, the flow of control is returned to the point immediately following where the method was called.