AP Computer Science a Flashcards: Scope And Access

Study Scope And Access in AP Computer Science a with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science a

Scope And Access

0 mastered0 still learning

0% Complete

QUESTION
1/ 71

What is the scope of a public class?

Tap card or press Space to flip

ANSWER

Accessible from any package. Public classes can be imported and used anywhere.

How well did you know it?

Card 1 / 71

What this deck covers

This deck focuses on Scope And Access, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science a.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: What is the scope of a public class?

Answer: Accessible from any package. Public classes can be imported and used anywhere.

Flashcard 2: Find the error: 'int x = 5; System.out.println(y);'

Answer: Variable 'y' is not declared. Variable y was never declared before being used.

Flashcard 3: What is the default value of a class-level int variable?

Answer:

  1. Numeric instance variables are automatically initialized to zero.

Flashcard 4: What does the static keyword imply for a method?

Answer: Belongs to the class, not instances. Can be called without creating an instance of the class.

Flashcard 5: Which keyword is used to declare a constant in Java?

Answer: final. Makes variables immutable after initialization.

Flashcard 6: Identify the error: 'int x; x++;'

Answer: Variable 'x' might not have been initialized. Local variables must be explicitly initialized before use.

Flashcard 7: Which keyword is used to access superclass methods?

Answer: super. References the parent class in inheritance hierarchy.

Flashcard 8: Identify the error: 'class A { private int x; } public class B extends A { x = 5; }'

Answer: Cannot access private member 'x'. Private members are not inherited by subclasses.

Flashcard 9: State the access level for a protected modifier.

Answer: Class, package, and subclasses. More restrictive than public, less than private.

Flashcard 10: Identify the error in: 'public static void main() { int x = 0; }'

Answer: Missing 'String[] args' in main method. Main method requires String array parameter to be valid entry point.

Flashcard 11: Which keyword is used to declare a constant in Java?

Answer: final. Makes variables immutable after initialization.

Flashcard 12: What is the scope of a variable declared in a class but outside methods?

Answer: Class-level scope. Instance variables are accessible throughout the entire class.

Flashcard 13: What is the lifetime of a local variable?

Answer: Until the method finishes. Local variables are destroyed when method execution ends.

Flashcard 14: What type of variable is shared among all instances of a class?

Answer: Static variable. Static variables belong to the class, not individual objects.

Flashcard 15: Identify the error: 'public class A { private int x; x = 5; }'

Answer: Assignment outside method or constructor. Assignment statements must be inside methods or constructors.

Flashcard 16: What is the purpose of the 'this' keyword?

Answer: Refers to the current object. Distinguishes instance variables from parameters with same names.

Flashcard 17: Which keyword is used to prevent method overriding?

Answer: final. Prevents subclasses from overriding the method.

Flashcard 18: Identify the error: 'int x; for(int i; i < 10; i++) { x++; }'

Answer: Variable 'x' might not have been initialized. Loop variable i is declared but not initialized.

Flashcard 19: Identify the error: 'class C { void method() { this = new C(); } }'

Answer: Cannot assign to 'this'. 'this' is a reference and cannot be reassigned.

Flashcard 20: What is the effect of the 'final' keyword on a class?

Answer: Class cannot be subclassed. Prevents the class from being extended by other classes.

Flashcard 21: Which access level allows visibility across different packages?

Answer: Public. Only access level that crosses package boundaries freely.

Flashcard 22: Identify the error: 'public class Test { private int x; x = 10; }'

Answer: Assignment outside method. Direct assignment statements must be inside methods or constructors.

Flashcard 23: What is the access level of a variable declared inside a block?

Answer: Local to the block. Block variables exist only within their enclosing braces.

Flashcard 24: What is the default value of a class-level int variable?

Answer:

  1. Numeric instance variables are automatically initialized to zero.

Flashcard 25: What is the effect of using a static import?

Answer: Allows static members to be used without class name. Enables direct use of static members without qualification.

Flashcard 26: Which access modifier allows subclass and package access?

Answer: protected. Provides inheritance access while maintaining some encapsulation.

Flashcard 27: Which keyword is used to prevent method overriding?

Answer: final. Prevents subclasses from overriding the method.

Flashcard 28: What is the scope of a method parameter?

Answer: Local to the method. Parameters are local variables passed to the method.

Flashcard 29: Identify the error in: 'public static void main() { int x = 0; }'

Answer: Missing 'String[] args' in main method. Main method requires String array parameter to be valid entry point.

Flashcard 30: Identify the error: 'class C { void method() { this = new C(); } }'

Answer: Cannot assign to 'this'. 'this' is a reference and cannot be reassigned.

Flashcard 31: What is the scope of a static method?

Answer: Accessible by class name. Static methods can be called using the class name directly.

Flashcard 32: What is the scope of a public class?

Answer: Accessible from any package. Public classes can be imported and used anywhere.

Flashcard 33: What is the scope of a static method?

Answer: Accessible by class name. Static methods can be called using the class name directly.

Flashcard 34: Identify the error: 'int x; for(int i; i < 10; i++) { x++; }'

Answer: Variable 'x' might not have been initialized. Loop variable i is declared but not initialized.

Flashcard 35: Identify the error: 'public class Test { private int x; x = 10; }'

Answer: Assignment outside method. Direct assignment statements must be inside methods or constructors.

Flashcard 36: What is the default access level for interface methods?

Answer: Public. Interface methods are implicitly public and abstract.

Flashcard 37: Which keyword restricts inheritance of a method?

Answer: final. Prevents methods from being overridden in subclasses.

Flashcard 38: Find the error: 'int x = 5; System.out.println(y);'

Answer: Variable 'y' is not declared. Variable y was never declared before being used.

Flashcard 39: What scope is limited to a method or constructor?

Answer: Local variable scope. Variables accessible only within their declaring method or constructor.

Flashcard 40: Identify the access level if no modifier is specified in Java.

Answer: Package-private. Default access when no explicit modifier is provided.

Flashcard 41: What scope is limited to a method or constructor?

Answer: Local variable scope. Variables accessible only within their declaring method or constructor.

Flashcard 42: Which access modifier allows subclass and package access?

Answer: protected. Provides inheritance access while maintaining some encapsulation.

Flashcard 43: What is the scope of a class variable?

Answer: Throughout the class. Instance variables are accessible from all methods in the class.

Flashcard 44: Which keyword is used to inherit a class in Java?

Answer: extends. Establishes inheritance relationship between classes.

Flashcard 45: What is the effect of using a static import?

Answer: Allows static members to be used without class name. Enables direct use of static members without qualification.

Flashcard 46: Which access level allows visibility across different packages?

Answer: Public. Only access level that crosses package boundaries freely.

Flashcard 47: What is the access level of a variable declared inside a block?

Answer: Local to the block. Block variables exist only within their enclosing braces.

Flashcard 48: Identify the error in: 'public void method() { return 0; }'

Answer: Void method cannot return a value. Void methods cannot use return statements with values.

Flashcard 49: What is the lifetime of a local variable?

Answer: Until the method finishes. Local variables are destroyed when method execution ends.

Flashcard 50: What keyword is used to create an instance of a class?

Answer: new. Allocates memory and creates object instances.

Flashcard 51: State the access level for a protected modifier.

Answer: Class, package, and subclasses. More restrictive than public, less than private.

Flashcard 52: What type of variable is shared among all instances of a class?

Answer: Static variable. Static variables belong to the class, not individual objects.

Flashcard 53: Identify the access level if no modifier is specified in Java.

Answer: Package-private. Default access when no explicit modifier is provided.

Flashcard 54: What is the scope of a variable declared as static?

Answer: Shared across all instances. One copy exists for the entire class, not per instance.

Flashcard 55: Identify the error in: 'public void method() { return 0; }'

Answer: Void method cannot return a value. Void methods cannot use return statements with values.

Flashcard 56: Identify the error: 'int x; x++;'

Answer: Variable 'x' might not have been initialized. Local variables must be explicitly initialized before use.

Flashcard 57: What is the scope of a method parameter?

Answer: Local to the method. Parameters are local variables passed to the method.

Flashcard 58: Identify the error: 'public class A { private int x; x = 5; }'

Answer: Assignment outside method or constructor. Assignment statements must be inside methods or constructors.

Flashcard 59: What does the static keyword imply for a method?

Answer: Belongs to the class, not instances. Can be called without creating an instance of the class.

Flashcard 60: What keyword is used to create an instance of a class?

Answer: new. Allocates memory and creates object instances.

Flashcard 61: Which keyword restricts inheritance of a method?

Answer: final. Prevents methods from being overridden in subclasses.

Flashcard 62: What is the scope of a variable declared in a class but outside methods?

Answer: Class-level scope. Instance variables are accessible throughout the entire class.

Flashcard 63: Which access modifier allows visibility only within its own class?

Answer: private. Most restrictive access level in Java.

Flashcard 64: What is the scope of a variable declared as static?

Answer: Shared across all instances. One copy exists for the entire class, not per instance.

Flashcard 65: What is the scope of a variable declared inside a method in Java?

Answer: Local to the method. Method variables are only accessible within that specific method.

Flashcard 66: Which keyword is used to access superclass methods?

Answer: super. References the parent class in inheritance hierarchy.

Flashcard 67: Which access modifier allows visibility only within its own class?

Answer: private. Most restrictive access level in Java.

Flashcard 68: What is the scope of a variable declared inside a method in Java?

Answer: Local to the method. Method variables are only accessible within that specific method.

Flashcard 69: What is the default access level for interface methods?

Answer: Public. Interface methods are implicitly public and abstract.

Flashcard 70: Identify the error: 'class A { private int x; } public class B extends A { x = 5; }'

Answer: Cannot access private member 'x'. Private members are not inherited by subclasses.

Flashcard 71: What is the effect of the 'final' keyword on a class?

Answer: Class cannot be subclassed. Prevents the class from being extended by other classes.