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

What are the differences between parameters and local variables?

Parameters: Passed into a method. | Local variables: Declared inside a method.

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

All Flashcards

What are the differences between parameters and local variables?

Parameters: Passed into a method. | Local variables: Declared inside a method.

What are the differences between method overloading and method overriding?

Overloading: Same name, different parameters. | Overriding: Same name and parameters, different implementation (in inheritance).

What are the differences between pass-by-value and pass-by-reference?

Pass-by-value: A copy of the value is passed. | Pass-by-reference: The memory address of the variable is passed (Java uses pass-by-value).

What are the differences between arguments and parameters?

Arguments: The actual values passed to a method when it is called. | Parameters: Variables in the method definition that receive the arguments.

What are the differences between formal and actual parameters?

Formal Parameters: Declared in the method signature. | Actual Parameters: The values passed during the method call.

What are the differences between instance and static methods?

Instance Methods: Belong to an instance of a class, can access instance variables. | Static Methods: Belong to the class itself, can only access static variables.

What are the differences between primitive and reference parameters?

Primitive Parameters: Pass-by-value, changes inside the method do not affect the original variable. | Reference Parameters: Pass-by-value (of the reference), changes inside the method can affect the original object.

What are the differences between using multiple parameters and using a single object as a parameter?

Multiple Parameters: Simple data types passed individually. | Single Object Parameter: Complex data types grouped into a single object, easier to manage related data.

What are the differences between void methods and methods that return a value?

Void Methods: Do not return a value, perform actions. | Methods with Return Value: Return a value after execution, can be used in expressions.

What are the differences between using parameters and using global variables?

Parameters: Scope is limited to the method, promotes modularity. | Global Variables: Scope is the entire program, can lead to unintended side effects.

What does the following code output?

java
public static void printValue(int x) {
 System.out.println(x + 5);
}

public static void main(String[] args) {
 printValue(10);
}

15

What does the following code output?

java
public static void printSum(double a, double b) {
 System.out.println(a + b);
}

public static void main(String[] args) {
 printSum(2.5, 3.5);
}

6.0

What does the following code output?

java
public static void greet(String name) {
 System.out.println("Hello, " + name + "!");
}

public static void main(String[] args) {
 greet("Alice");
}

Hello, Alice!

Identify the error in the following code:

java
public static void square(int x) {
 return x * x;
}

public static void main(String[] args) {
 int result = square(5);
 System.out.println(result);
}

The square method is declared as void but attempts to return a value. It should be declared with a return type of int.

What does the following code output?

java
public class Example {
 public static void modify(int num) {
 num = num * 2;
 }

 public static void main(String[] args) {
 int x = 5;
 modify(x);
 System.out.println(x);
 }
}

5

What does the following code output?

java
public class Overload {
 public static void print(int x) {
 System.out.println("Integer: " + x);
 }
 public static void print(double x) {
 System.out.println("Double: " + x);
 }
 public static void main(String[] args) {
 print(5);
 print(5.0);
 }
}

Integer: 5 Double: 5.0

What does the following code output?

java
public class Test {
 public static void method(int a, double b) {
 System.out.println("int, double");
 }
 public static void method(double a, int b) {
 System.out.println("double, int");
 }
 public static void main(String[] args) {
 method(5, 5.0);
 }
}

int, double

Identify the error in the following code:

java
public class ErrorExample {
 public static void calculate(int a, int b) {
 int result = a + b;
 }
 public static void main(String[] args) {
 System.out.println(calculate(5, 3));
 }
}

The calculate method is void and does not return a value. The main method attempts to print the result of calculate(5, 3), which is not possible.

What does the following code output?

java
public class ScopeTest {
 static int x = 10;
 public static void modify(int x) {
 x = x + 5;
 System.out.println("Method x: " + x);
 }
 public static void main(String[] args) {
 modify(x);
 System.out.println("Main x: " + x);
 }
}

Method x: 15 Main x: 10

What does the following code output?

java
public class Division {
 public static void divide(double a, double b) {
 if (b == 0) {
 System.out.println("Cannot divide by zero");
 } else {
 System.out.println(a / b);
 }
 }
 public static void main(String[] args) {
 divide(10.0, 0.0);
 }
}

Cannot divide by zero

How are methods with parameters used in a calculator application?

Methods like add(double a, double b) and subtract(double a, double b) take numbers as parameters to perform calculations.

How are methods with parameters used in a string manipulation program?

A method like substring(int startIndex, int endIndex) takes indices as parameters to extract a portion of a string.

How are methods with parameters used in a graphics application?

A method like drawCircle(int x, int y, int radius) takes coordinates and radius as parameters to draw a circle on the screen.

How is method overloading used in a banking application?

The deposit method can be overloaded to accept different parameter types, such as deposit(double amount) for depositing a specific amount or deposit(Check check) for depositing a check.

How are methods with parameters used in a game development context?

Methods like moveCharacter(int x, int y) or dealDamage(int damageAmount) take parameters to update the game state based on player actions or game events.

How are methods with parameters used in data analysis?

Methods like calculateAverage(double[] data) or findMaxValue(int[] data) take data sets as parameters to perform statistical calculations.

How are methods with parameters used in web development?

Methods like displayUserProfile(String userID) or submitForm(FormData formData) take parameters to retrieve and process user data.

How are methods with parameters used in machine learning?

Methods like trainModel(double[][] features, int[] labels) or predict(double[] input) take data sets and input features as parameters to train models and make predictions.

How are methods with parameters used in robotics?

Methods like moveArm(int angle1, int angle2, int angle3) or activateSensor(int sensorID) take parameters to control robot movements and sensor activations.

How are methods with parameters used in operating systems?

Methods like createProcess(String processName, int priority) or allocateMemory(int size) take parameters to manage system resources and processes.