Unit 1 — Using Objects and Methods

Use the topic links below to study. After that, take the Unit 1 practice quiz: 15 multiple-choice (AP-style) + 1 short FRQ.

How to use the quiz

  • Answer the 15 MCQs first (don’t peek).
  • Click Check Answers to see score + explanations.
  • Try the FRQ, then reveal the sample solution.

Unit 1 Quiz — Multiple Choice (15)

Choose the best answer. (One correct option each.)

1) Which statement best describes an algorithm?

Topic 1.1

2) Consider the code segment below. What happens when it is compiled?

Topic 1.1
int x = 4
int y = 5;

3) What is the value of y after the code executes?

Topic 1.2–1.3
int x = 3;
double y = x / 2;

4) Which line correctly reads an int from the keyboard using Scanner named in?

Topic 1.4

5) What is printed by the code segment?

Topic 1.5
System.out.println((double) 5 / 2);

6) What is the value of a after the code executes?

Topic 1.6
int a = 5;
a += 3 * 2;

7) Which import statement allows a program to use the Scanner class?

Topic 1.7

8) Which comment best documents a precondition for a method?

Topic 1.8

9) Which part of the method header below is the return type?

Topic 1.9
public static int add(int a, int b)

10) Which call correctly invokes a class method from the Math class?

Topic 1.10–1.11

11) Which statement compiles correctly?

Topic 1.11

12) In the code below, what best describes s?

Topic 1.12
String s = "hello";

13) Which line demonstrates instantiation (creating a new object)?

Topic 1.13

14) What is the value of t after the code executes?

Topic 1.14
String word = "Java";
String t = word.substring(1, 3);

15) What is printed by the code segment?

Topic 1.15
String s = "ab";
s = s + "cd";
System.out.println(s.length());

Unit 1 Quiz — FRQ (1)

This is a short “Unit 1 style” FRQ: strings + method signature + simple expressions (no loops/conditionals needed).

FRQ 1) makeUsername

Write a static method makeUsername that creates a username from a first and last name.

  • The method header must be: public static String makeUsername(String first, String last)
  • Return a String in the format: lowercase first initial + lowercase last name.
  • Assume first and last each contain at least 1 character.
  • Examples:
    • makeUsername("Jake", "Sully") returns "jsully"
    • makeUsername("Ada", "Lovelace") returns "alovelace"

Write your solution here: