AP Computer Science a Flashcards: Class Variables And Methods

Study Class Variables And Methods 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

Class Variables And Methods

0 mastered0 still learning

0% Complete

QUESTION
1/ 69

What is the main disadvantage of using class variables extensively?

Tap card or press Space to flip

ANSWER

Increased coupling. Global state creates dependencies between classes.

How well did you know it?

Card 1 / 69

What this deck covers

This deck focuses on Class Variables And Methods, 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 main disadvantage of using class variables extensively?

Answer: Increased coupling. Global state creates dependencies between classes.

Flashcard 2: State whether class methods can be abstract.

Answer: No. Abstract requires inheritance; static methods cannot be overridden.

Flashcard 3: What is the primary use of static import?

Answer: Access static members without class name. Allows direct access to static members without qualification.

Flashcard 4: Can a static method be final?

Answer: Yes. Final prevents method from being overridden.

Flashcard 5: Can class methods be overloaded in Java?

Answer: Yes. Multiple methods with same name but different parameters.

Flashcard 6: Which keyword is used to synchronize a class method?

Answer: synchronized. Synchronized ensures thread-safe access to the method.

Flashcard 7: What is the default value of a class variable of type boolean?

Answer: false. Boolean primitive type defaults to false.

Flashcard 8: Which keyword should be used to ensure a class variable cannot be changed?

Answer: final. Final prevents reassignment after initialization.

Flashcard 9: Identify the error: modifying a final class variable.

Answer: Final variables cannot be reassigned. Final variables are constants after initialization.

Flashcard 10: Can class methods access instance variables directly?

Answer: No. Static context cannot access non-static members directly.

Flashcard 11: Which keyword is used to synchronize a class method?

Answer: synchronized. Synchronized ensures thread-safe access to the method.

Flashcard 12: Can a static method be final?

Answer: Yes. Final prevents method from being overridden.

Flashcard 13: What is the result of calling a non-static method from a static context?

Answer: Compilation error. Static context cannot access non-static members.

Flashcard 14: Can a static method call another static method in the same class?

Answer: Yes. Static methods can call other static members directly.

Flashcard 15: In which memory area are class variables stored?

Answer: Method Area. Static variables are stored in the method area of memory.

Flashcard 16: Identify the error: modifying a final class variable.

Answer: Final variables cannot be reassigned. Final variables are constants after initialization.

Flashcard 17: What is the main purpose of a static block?

Answer: Initialize static variables. Static blocks run once when class is first loaded.

Flashcard 18: Identify the error: static method trying to override an instance method.

Answer: Static methods cannot override instance methods. Static methods cannot participate in polymorphism.

Flashcard 19: What is the primary characteristic of a static nested class?

Answer: Does not require an instance of the outer class. Static nested classes don't need outer class instances.

Flashcard 20: State the keyword used to prevent inheritance of a class method.

Answer: final. Final prevents method from being overridden in subclasses.

Flashcard 21: Find the error: accessing instance variable from a static method.

Answer: Static methods cannot access instance variables directly. Static methods need object reference for instance variables.

Flashcard 22: What is the primary advantage of using class variables?

Answer: Shared data among all instances. One copy exists for all objects of the class.

Flashcard 23: Determine if a class method can be called using an instance.

Answer: Yes, but not recommended. Compiler allows but style guides discourage this practice.

Flashcard 24: State the default value of a class variable of type double.

Answer: 0.0. Floating-point primitive types default to 0.0.

Flashcard 25: What is the result of accessing a static variable with an instance?

Answer: Valid but discouraged. Works but using class name is clearer style.

Flashcard 26: Can a static method call another static method in the same class?

Answer: Yes. Static methods can call other static members directly.

Flashcard 27: Can class methods be overridden in subclasses?

Answer: No. Static methods belong to class, cannot be overridden.

Flashcard 28: Identify the keyword used to declare a class method.

Answer: static. Makes the method belong to the class, not instances.

Flashcard 29: What is the default value of a class variable of type int?

Answer:

  1. Numeric primitive types default to zero.

Flashcard 30: Which keyword should be used to ensure a class variable cannot be changed?

Answer: final. Final prevents reassignment after initialization.

Flashcard 31: Choose the correct way to call a class method 'compute' from class 'MathUtils'.

Answer: MathUtils.compute(). Use ClassName.methodName() syntax for static methods.

Flashcard 32: Find the error: accessing instance variable from a static method.

Answer: Static methods cannot access instance variables directly. Static methods need object reference for instance variables.

Flashcard 33: State whether class methods can be abstract.

Answer: No. Abstract requires inheritance; static methods cannot be overridden.

Flashcard 34: What is a class variable in Java?

Answer: A variable declared with the static keyword, shared by all instances. Belongs to the class itself, not individual objects.

Flashcard 35: Identify the error: static method trying to override an instance method.

Answer: Static methods cannot override instance methods. Static methods cannot participate in polymorphism.

Flashcard 36: What is the primary advantage of using class variables?

Answer: Shared data among all instances. One copy exists for all objects of the class.

Flashcard 37: What is the main purpose of a static block?

Answer: Initialize static variables. Static blocks run once when class is first loaded.

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

Answer: Entire class. Class variables exist at the class level globally.

Flashcard 39: Identify the order of execution for static blocks and class variables.

Answer: Static variables first, then static blocks. Static initialization follows declaration order in source code.

Flashcard 40: What is the primary characteristic of a static nested class?

Answer: Does not require an instance of the outer class. Static nested classes don't need outer class instances.

Flashcard 41: What is the visibility modifier for a class variable visible only within its package?

Answer: default. Default means package-private visibility.

Flashcard 42: What is a class method in Java?

Answer: A method declared with the static keyword, can be called without an instance. Belongs to the class, accessible without creating objects.

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

Answer: Entire class. Class variables exist at the class level globally.

Flashcard 44: Choose the correct way to call a class method 'compute' from class 'MathUtils'.

Answer: MathUtils.compute(). Use ClassName.methodName() syntax for static methods.

Flashcard 45: Identify the keyword used to declare a class variable.

Answer: static. Makes the variable belong to the class, not instances.

Flashcard 46: What is the effect of declaring a method as static?

Answer: Belongs to the class, not instances. Static members are associated with the class itself.

Flashcard 47: What happens if a class variable is not initialized?

Answer: Default value is assigned. Java automatically assigns default values to static variables.

Flashcard 48: Determine if class methods can access static variables.

Answer: Yes. Static methods can access other static members.

Flashcard 49: Identify the visibility modifier for a class variable accessible to all classes.

Answer: public. Public modifier allows access from any class.

Flashcard 50: Determine if a class method can be called using an instance.

Answer: Yes, but not recommended. Compiler allows but style guides discourage this practice.

Flashcard 51: Identify the order of execution for static blocks and class variables.

Answer: Static variables first, then static blocks. Static initialization follows declaration order in source code.

Flashcard 52: What is the default value of a class variable of type int?

Answer:

  1. Numeric primitive types default to zero.

Flashcard 53: Can a class variable be private?

Answer: Yes. Private restricts access to the declaring class only.

Flashcard 54: Can class methods be overridden in subclasses?

Answer: No. Static methods belong to class, cannot be overridden.

Flashcard 55: What is the main disadvantage of using class variables extensively?

Answer: Increased coupling. Global state creates dependencies between classes.

Flashcard 56: Determine the visibility of a class method declared with no modifier.

Answer: Package-private. No access modifier means package-private visibility.

Flashcard 57: What happens if a class variable is not initialized?

Answer: Default value is assigned. Java automatically assigns default values to static variables.

Flashcard 58: What is a class method in Java?

Answer: A method declared with the static keyword, can be called without an instance. Belongs to the class, accessible without creating objects.

Flashcard 59: What is the default value of a class variable of type boolean?

Answer: false. Boolean primitive type defaults to false.

Flashcard 60: Determine the visibility of a class method declared with no modifier.

Answer: Package-private. No access modifier means package-private visibility.

Flashcard 61: Identify the keyword used to declare a class variable.

Answer: static. Makes the variable belong to the class, not instances.

Flashcard 62: State the default value of a class variable of type double.

Answer: 0.0. Floating-point primitive types default to 0.0.

Flashcard 63: Identify the visibility modifier for a class variable accessible to all classes.

Answer: public. Public modifier allows access from any class.

Flashcard 64: Determine if class methods can access static variables.

Answer: Yes. Static methods can access other static members.

Flashcard 65: What is the result of accessing a static variable with an instance?

Answer: Valid but discouraged. Works but using class name is clearer style.

Flashcard 66: What is the visibility modifier for a class variable visible only within its package?

Answer: default. Default means package-private visibility.

Flashcard 67: In which memory area are class variables stored?

Answer: Method Area. Static variables are stored in the method area of memory.

Flashcard 68: State the keyword used to prevent inheritance of a class method.

Answer: final. Final prevents method from being overridden in subclasses.

Flashcard 69: What is the primary use of static import?

Answer: Access static members without class name. Allows direct access to static members without qualification.