AP Computer Science A: Class Creation

0.0(0)
studied byStudied by 1 person
0.0(0)
linked notesView linked note
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/28

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

29 Terms

1
New cards

Class

A blueprint or template for creating objects that defines attributes (fields) and behaviors (methods).

2
New cards

Object

An instance of a class that contains its own unique data and can perform actions defined by the class.

3
New cards

Field (Attribute)

A variable declared inside a class but outside any method, used to store data about an object.

4
New cards

Method

A function defined inside a class that performs operations or actions on the object’s data.

5
New cards

Constructor

A special method used to initialize new objects of a class; has the same name as the class and no return type.

6
New cards

Default Constructor

A no-argument constructor automatically provided by Java if no constructor is explicitly defined.

7
New cards

Parameterized Constructor

A constructor that accepts arguments to initialize object fields with specific values

8
New cards

Overloaded Constructor

Multiple constructors in the same class with different parameter lists, allowing varied ways to initialize objects

9
New cards

Encapsulation

The practice of hiding internal data using private fields and providing controlled access through public methods

10
New cards

Access Modifier

Keywords that control visibility of class members: public, private, protected, or default (package-private)

11
New cards

Public Access Modifier

Allows the member or class to be accessible from anywhere in the program

12
New cards

Private Access Modifier

Restricts access to within the same class; used to protect object data

13
New cards

Protected Access Modifier

Allows access within the same package and by subclasses

14
New cards

Getter Method

A public method that returns the value of a private field (e.g., getName())

15
New cards

Setter Method

A public method that modifies a private field, often with input validation (e.g., setAge(int a))

16
New cards

this Keyword

Refers to the current object instance; used to distinguish between instance variables and parameters

17
New cards

Static Field

A variable shared by all instances of a class, belonging to the class rather than individual objects.

18
New cards

Static Method

A method that belongs to the class instead of instances; called using the class name (e.g., Math.sqrt(9)).

19
New cards

Composition

A relationship where one class contains another as a field, representing a “has-a” relationship (e.g., a Car has an Engine)

20
New cards

Class Naming Convention

Class names should begin with a capital letter and use CamelCase (e.g., BankAccount, StudentRecord).

21
New cards

Method Naming Convention

Methods use lowerCamelCase (e.g., calculateTotal, printReceipt).

22
New cards

Field Naming Convention

Fields typically use lowerCamelCase (e.g., balance, studentName).

23
New cards

Modularity

Designing a class to perform one clear purpose, improving code organization and reusability

24
New cards

Data Hiding

Keeping fields private so external code cannot modify them directly, enforcing encapsulation.

25
New cards

Validation in Setters

Adding checks in setter methods to prevent invalid data from being stored in fields

26
New cards

Class Composition Example

A Car class that includes an Engine object to represent its internal mechanism

27
New cards

Common Class Design Mistake

Forgetting to initialize fields, misusing static variables, or neglecting access control

28
New cards

Best Practice in Class Design

Keep one class per file, use private fields, descriptive names, and clear comments.

29
New cards

Fully Encapsulated Class

A class where all fields are private and can only be accessed or modified through public methods.