zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcard
Study GuideStudy GuideQuestion BankQuestion BankGlossaryGlossary

How does pass-by-value affect primitive variables?

Changes to the parameter inside the method do not affect the original variable outside the method.

Flip to see [answer/question]
Flip to see [answer/question]
Revise later
SpaceTo flip
If confident

All Flashcards

How does pass-by-value affect primitive variables?

Changes to the parameter inside the method do not affect the original variable outside the method.

How does pass-by-value affect reference variables?

Changing the object's state (e.g., using a setter) inside the method affects the original object outside the method.

What is the general format of a method header in Java?

()

Why should mutable objects passed as parameters be handled carefully?

Modifications within the method can unintentionally alter the object's state outside the method.

What determines a method's accessibility?

The access modifier (public, private, protected) used in the method header.

What is the role of parameters in a method?

To receive input values that the method uses during its execution.

What is the significance of the return type in a method?

It specifies the data type of the value that the method returns to the caller.

What does the @Override annotation indicate?

That a method in a subclass is overriding a method from its superclass.

What are the common access modifiers in Java?

public, private, and protected.

What is the purpose of Javadoc comments?

To document the purpose, parameters, and return values of methods for API documentation.

What does the following code output?

java
Assignment a = new Assignment(true);
System.out.println(a.gradeAssignment(false));

false

What does the following code output?

java
Student s = new Student(10, "John Doe", 16);
System.out.println(s.getGradeLevel());

10

Identify the error in the following code:

java
public class Student {
  private int age;

  public void setAge(String newAge) {
    age = newAge;
  }
}

The setAge method attempts to assign a String value to an integer variable age. The parameter type should be int.

What does the following code output?

java
Student s = new Student(9, "Jane Smith", 14);
System.out.println(s.returnCurrentAssignment());

null

Identify the error in the following code:

java
public class Assignment {
  private boolean correctAnswer;

  public Assignment(boolean answer) {
    correctAnswer = answer
  }
}

Missing semicolon at the end of the correctAnswer = answer statement inside the Assignment constructor.

What does the following code output?

java
Assignment a = new Assignment(true);
System.out.println(a.toString());

This is an assignment with correct answer true

Complete the following code snippet to increment assignmentsComplete:

java
public class Student {
  private int assignmentsComplete = 0;

  public void incrementAssignments() {
    // Complete this method
  }
}
java
assignmentsComplete++;

What does the following code output?

java
Student s = new Student(11, "Peter Jones", 17);
s.setName("Robert Jones");
System.out.println(s.getName());

Robert Jones

Identify the error in the following code:

java
public class Student {
  private int gradeLevel;

  public void setGradeLevel(String level) {
    gradeLevel = level;
  }
}

The setGradeLevel method attempts to assign a String value to an integer variable gradeLevel. The parameter type should be int.

What does the following code output?

java
Student s = new Student(12, "Alice Brown", 18);
System.out.println(s.getGradeDecimal());

0.0

What is pass-by-value?

A method receives a copy of the variable's value; changes inside the method do not affect the original variable outside.

What is a reference variable?

A variable that stores the memory address of an object.

What is an access modifier?

Keywords in Java that control the visibility and accessibility of classes, methods, and variables.

What is the return type of a method?

The data type of the value that a method returns after its execution.

What is a parameter in a method?

A variable that receives a value passed into a method.

What is a method header?

The first line of a method definition, including access modifier, return type, method name, and parameters.

What is a mutable object?

An object whose state can be modified after it is created.

What is a getter method?

A method used to retrieve the value of an object's attribute.

What is an instance variable?

A variable defined in a class for which every object of the class has its own copy.

What is the purpose of the 'void' return type?

Indicates that the method does not return any value.