Creating and Storing Objects

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/17

flashcard set

Earn XP

Description and Tags

Adv. Comp Sci, Lesson 2.3 - Creating and Storing Objects

Last updated 2:41 AM on 10/3/24
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

18 Terms

1
New cards

OOP

A programming style where users declare classes, create objects from classes, and write programs with interacting objects.

2
New cards

Object

An instance that can be used in code as an instance variable (state) and a method (behavior).

3
New cards

Class

A template or blueprint from which an object can be created, defining the object's data and methods.

4
New cards

Instance Variable

A variable that defines what data objects will use; they are private and declared without initial values.

public class Dog {
private int age;
private String name;
private boolean goodDog;
}

5
New cards

Constructor

A special method that makes an object public and saves memory to give instance variables values; it does not return values.

int age = 0; 
String name = "unknown"; 
boolean goodDog = false; 

6
New cards

Default Constructor

A constructor with no parameters that initializes instance variables to default values.

int age = 0; 
String name = "unknown"; 
boolean goodDog = false; 

7
New cards

Parameter Constructor

A constructor that uses the memory saved from the default constructor to add values to the instance variables; can have unlimited uses throughout the class.

public class Dog
{
   //instance variables here
   //default constructor here

   public Dog(String n, int a, boolean g)
   {
 
      this.name = n;
      this.age = a;
      this.goodDog = g;
 
   }
}


Creating Behaviors

8
New cards

"this" Keyword

Used in parameter constructors to differentiate between instance variables and parameters with the same name.

this.name = n;
this.age = a;
this.goodDog = g;
 

9
New cards

Methods

Behaviors that objects can have, which can be public or private depending on their accessibility in classes.

10
New cards

Why are instance variables private?

Back: Instance variables are kept private to encapsulate the data, meaning methods outside of the main class cannot access it.

11
New cards

What are instance variables not given when they are declared?

When they are declared, their variables are not assigned values.

12
New cards

Why are constructor variables given default values?

Ensures that the objects are at a known state to prevent errors from uninitialized variables.

13
New cards

What do parameter constructors list when giving values to variables?

the variable identifier and the data type.

14
New cards

reference memory

memory used to store data and objects in a program. It refers to certain instance variables.

15
New cards

What are reference variables used for?

To refer to methods in the object creating class.

16
New cards

void type

a method that does not return data.

17
New cards

relationship between parameters and methods

Parameters are inputs that methods use to perform actions and calculations. Sometimes they can modify variables.

18
New cards