CSA - Unit 2

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/29

flashcard set

Earn XP

Description and Tags

send help

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

30 Terms

1
New cards

Objects

  • Something being created/ manipulated by the program

  • Characterized by it’s state and behavior

  • Instance of a class

2
New cards

Object Reference

  • A variable that represents an object

3
New cards

Class

  • Encapsulates data

  • An object is an instance of a class

4
New cards

Public class

  • Usable by all client programs (pieces of code outside the class)

    • All classes are public in AP Java subset

5
New cards

Public Methods

  • Accessible to all client programs

6
New cards

Private Methods/Variables

  • Can only be accessed by methods in the same class

7
New cards

Static Variable (Class Variable)

  • Memory allocation only happens once

    • Shared by ALL INSTANCES of the class

8
New cards

Static Final Variable (constant)

  • Cannot be changed

  • Public

  • Single value that applies to the whole class instead of a new instance for each object of the class

    • BankAccount.PENALTY for client

    • PENALTY in own class

9
New cards

Method Header

Public void Withdraw (String password, double amount)

Access Specifier | Return Type | Method Name | Parameter List

  • Access specifier = who has access

  • Void = method doesn’t return a value

    • Parameters are separated by commas, require data type

  • Implementation follows header and is enclosed by {}

10
New cards

Constructor

  • Method that creates an object of the class

    • Name is same as class, no return type

11
New cards

No-Argument Constructor

  • No parameters

    • Provides initial values for an object

12
New cards

Reference to an Object

  • Variable assigned values of the object

13
New cards

Constructor with parameters

  • Sets instance variables to values of those parameters

    • They can be changed in different references

14
New cards

Accessor Method

  • Public method that accesses a class object without altering it

    • .getBalance

15
New cards

Mutator Method

  • Changes state of an object by modifying at least one instance variable

16
New cards

Instance Methods

  • Perform operations on individual objects of a class

  • Constructors, accessors, mutators

17
New cards

Static Methods

  • Perform an operation for the entire class

  • Keyword Static in header

    • Can use a static variable in its code

18
New cards

Driver Class

  • Main() method is always static

    • Tests other classes

19
New cards

Method Overloading

  • 2 or more methods in the same class with the same name but different parameter lists

  • Distinguished by method SIGNATURE

    • Can’t have 2 methods with same signature but different return types, so return type is irrelevant

20
New cards

Scope

  • Region in which the variable/ method is visible and can be accessed

  • A class’s instance + static variables and methods belong to the class’s scope (enclosed by {})

    • DOT OPERATOR NOT NEEDED

21
New cards

Local Variable

  • Defined inside a method or statement

    • Scope is from declaration to end of its block

  • Precedence over instance variables with same name

22
New cards

Block

  • Piece of code enclosed by {}

23
New cards

This Keyword

  • Instance methods are called for a particular object, which is an IMPLICIT PARAMETER for the method

    • Referred to with keyword this

24
New cards

Reference Data Types

  • Objects and arrays

  • String, Random, int[], string [] [], Cat, etc

  • STORES MEMORY ADDRESSES

    • If object is changed, any references aliased to it will also change

25
New cards

Primitive Data Types

  • Double, int, char, boolean

    • STORES VALUE DIRECTLY

26
New cards

Null Reference

  • Uninitialized object variable

  • Null pointer

  • Doesn’t refer to an object

27
New cards

Formal Parameters

  • Placeholders for actual parameters

  • String acctPassword, Double amount

28
New cards

Actual Parameters

  • Actual values given to a method call

  • Match up with formal parameters

29
New cards

Primitive Types as Parameters

  • Changes made to parameters of method will not affect the values of the arguments in the calling program

  • Basically goes back to what it was before

  • Passed by value

30
New cards

Objects as Parameter