Game Basics Class
GCC Academy
Hello everyone
I am Lee Yeong-hoon, in charge of this C#-based Object-Oriented Programming Lecture
This unit covers object-oriented programming
and the core topic of classes
We will explore the concept of classes and objects,
learning how to initialize them using constructors
Additionally, we’ll examine the principles of object-oriented programming,
abstraction, inheritance, encapsulation, and polymorphism,
and learn how to implement these through coding
Understanding Object-Oriented Programming and Classes
A class,
also referred to as a user-defined data type,
in a more detailed way,
represents a space containing attributes and functions
It contains things like
attributes and functions
Last time,
we learned about variables and functions
Attributes function like variables,
while functions represent actions or methods
And function literally means a function
So we say a class functions as a function
or a method
That's another way of saying it
In there, we have attributes or functions
that are also called fields
In C#, attributes inside a class are
specifically referred to as fields
In other words,
we can say a member variable or a member function
In Unity development using C#,
the naming conventions follow specific rules
Variables are often nouns,
and functions, verbs
For instance, a Human class
could have fields like age,
name,
and gender,
and maybe height too
A Human class can have attributes such as these
It can also include functionalities
like walking
and sitting
This is essentially how a class is structured
Within a class, you can include constructs
like if statements like so
or for loops to define the logic of its methods
That's how classes are composed of
Classes are described as user-defined data types
With these user-defined data types, you can create variables,
or objects
Variables created using a class are referred
to as objects in programming
Objects,
in English
An object
Sometimes, it is also referred to as an instance
While object and instance are related,
not exactly the same,
as in they refer to a variable that exists
But they carry slightly different meanings
An instance refers to a specific existence,
whereas an object refers to a role or functionality within the system
For example, a Human class
can be used to create specific objects
like Yeonghee or Cheolsu
Right
Let’s say we create an object called Cheolsu
Cheolsu is an instance of the Human class
Inheritance is a concept within a class
that allows it to transform into a different class
This transformation can change the roles associated with the class,
which is the essence of an object
For example, Cheolsu is his parents’ son
At school, he is a friend to his classmates,
so his role is a friend,
and in his relationship with his teacher, he is a student
If Cheolsu has a job,
such as being a department manager in a company,
he assumes the role of a manager in that context
Although Cheolsu is the same entity,
he performs different roles based on the situation,
which illustrates the concept of objects as adaptable entities
Instances, in contrast, refer to the actual existence
of something in memory
In this context, it is referred to as an instance
For class,
a class also has special concepts,
which includes
things such as inside and outside the class
For instance, a class can contain another class
Right
This creates the distinction between the inner part and the outer part of the class
This distinction involves concepts
like granting access permissions to the information
inside the class from other classes outside it
This is called access modifiers or access specifiers
I’ll use the term access modifier
For example, a class may have attributes like age, name, and gender
Let’s say you want gender to be accessible internally
but hidden externally
Right
In such cases, you can make it public,
private,
or conditionally accessible
within inheritance relationships,
but hidden externally
Visible or invisible to
the parent-child relationships
Public means fully accessible,
private means completely hidden,
and protected means accessible
within inheritance relationships but hidden elsewhere
These keywords
allow you to control access to attributes
or functions using access modifiers
Like this
Additionally,
When we learned about functions,
we discussed internal and external concepts
And when there’s a variable, accessing it is also part of this
Remember?
A variable outside the function
is typically called a field
For instance,
let’s say there’s a variable called money
A variable called money
This variable money can also exist inside the walk function,
and the sit function can also have its own money variable
When accessing these,
the money inside the walk function is only accessible within walk
This is called a local variable
This is a member variable
or a field
I'll stick to field
So this is a local variable too
So, if sit refers to money, it refers to its own money variable
Similarly, walk’s money refers to its own money
Right
Therefore, internal variables
are prioritized when accessed
But sometimes, you may want to access the external field instead
To do this, you use
something before this name, money
for a field, it's this.money
This means
that the field is outside
By clearly indicating whose property it is,
access becomes possible
Using these characteristics of classes,
we can perform object-oriented programming
Next
is object-oriented programming,
which is object,
and oriented,
and now programming
It involves creating everything as objects
and programming through their interactions
That's the object oriented programming,
or OOP when abbreviated
OOP has four main features,
inheritance,
the ability to inherit,
abstraction,
encapsulation,
or hiding,
and polymorphism
Let me explicate
Inheritance allows a parent-child relationship between classes
For example,
let's say we have class A and B
Class A with a name variable and a walk function can be inherited by class B,
which then gains A’s features and can add its own
When class B inherits class A, this is what it looks like
This is class B,
inheriting class A, like this Of course, the child B is bigger than its parent A
So we can say name, walk, and everything
We can also add member variables and functions in class B here
So again, inheritance allows a parent-child relationship between classes
Now, abstraction is something we're familiar with unclear things
Abstraction simplifies complex structures by only implementing necessary features
For instance, let's create a human class
For instance, a human class might include a lot of attributes
When programming, creating a human involves reducing and simplifying what a human can do
or what information it holds, for example, a human class might only need the ability to walk
and speak to serve its purpose
Instead of implementing everything a human can do,
abstraction involves designing and implementing only the essential features required for the task
Encapsulation, as the term suggests, means hiding information
Earlier I mentioned access modifiers, including public,
private,
and protected
These are the three concepts
Public, private, and protected
Partial access
means making something public in a parent-child relationship
but private to external classes
In this case, we use private or protected
protected is used to limit access
to specific relationships
while keeping it hidden from others,
for instance the name
So external classes
cannot have access to this member, or this class
Preventing access to certain properties
or functionalities is called encapsulation
Blocking access entirely is not always ideal
Encapsulation is often used instead
Imagine receiving a capsule pill
from a pharmacy
labeled as a cold medicine
It's a capsule,
a pill that looks like this
Let's say this is our cold pill
When you take the pill,
you expect it to cure your cold,
but you don’t necessarily know
or care about the exact ingredients inside
You focus on
its functionality rather than its internal composition
Similarly, encapsulation
in a class means using its functions
without needing to understand
the detailed implementation inside,
trusting that it’s properly set up
That's encapsulation
To enable encapsulation, access specifiers are used
Lastly, there’s polymorphism,
so polymorphism in English
It comes from polymorph
For those familiar with fantasy novels,
you might recognize the term polymorph
use to transform into human shapes
and secretly live among people
In that case,
polymorph is the magic spell to change that body
In programming,
polymorphism refers to having multiple forms
or appearances in general
When a class is inherited,
for that inheritance,
an object,
or an instance,
looks like this
For instance, if I create
an instance using class B,
like this,
it follows
the structure of class B if I want it to
However, I can also cast this instance into the form of class A
his transformation is called casting
Type conversion,
also called type casting,
is possible
but only so under the condition of
when classes are in an inheritance relationship
For classes,
the unrelated classes
without an inheritance structure,
type conversion is not allowed
So it can only happen when it has inherited it
When type casting is performed,
with the conversion,
the actual memory size of the object remains unchanged,
but access to members is restricted by the converted type
For example, if an instance created as type B
is forcibly cast to type A,
you can only access members of type A
This allows the object’s form to change like so
Although this example only involves two types,
you can continue inheriting and transforming forms
This ability to change forms through type casting
is referred to
as polymorphism
An object,
through type casting,
can take on different appearances,
which is what polymorphism signifies
So that's what polymorphism does
Constructors, Inheritance, Encapsulation, and Polymorphism
Now, let’s create a project
to practice coding
Right-click on the solution, choose Add,
and then New Project
Select ‘Console App .NET Framework,
click Next,
and name it Class
Like so, Class
Now, Create
n the initial setup, you’ll see the default structure
includes a class Program declaration
It may also include the internal keyword,
which might seem complex,
but simply put,
it restricts access to within the same program
It’s somewhat similar to protected
When developing an application,
other applications could potentially
access certain functions or members
by traversing memory
The internal keyword
ensures that only components
within the same application can access those members,
or within the same binary,
preventing external access
The internal keyword is used to handle access
protection in this way
It’s a concept I believe is specific to C#
So now,
while many might think
C# only has public, private, and protected,
there’s one more
in C#
So this is,
it's like protected,
or even public in a way
Now, let’s create a class
Outside the main program,
we’ll add a new class declaration
ll call it Animal. Start with class Animal
and add curly braces to define its structure.
Now,
this creates the class,
but if you want it
to be used anywhere publicly,
such as creating an object like Class.Animal
In making an object like this, I recommend
that you make it public
Add the public keyword
to allow access from anywhere
So it looks like this
Now, let’s add
some members to this Animal class
First, we’ll define a member variable
and a function
I'll make these two now
Let’s create
a public member variable called name
Public
We’ll write it as public string name
Then, we’ll create an object from this class
In the Main method, we’ll declare an object of the Animal class
Since a class acts as a data type,
a data type,
we write the class name followed by the variable name,
such as Animal animal
So notice that this class
is what we just created
So, a class variable created with a user-defined data type
is called an object
In C#, you can’t just create an object like this
So how do you create one?
You leave a space, use the = operator,
and then use the new keyword to create it
Then, you leave a space,
write the name of the class,
and finally add parentheses at the end
By doing this, the class is created
Now, I’ll try printing the name inside this class
I’ll write it like this and use
Console.WriteLine
to output the name of the animal
However, since the name currently has no value,
it will simply print an empty space
Ah, I forgot to set it
After selecting the class
and setting it as the startup project, I’ll run it
When executed, nothing will be displayed,
just a blank line, as you can see
Now, I want to assign a name
Look here
I’ll assign ‘animal’ to the name of animal,
like animal
So this prints animal correctly
But creating an object like this
and manually assigning a value every time feels inconvenient
So, I want the name field to automatically have animal
when an animal object is created
For this, we use a special function
called a constructor
A constructor function
is a function automatically called
when an object is created from a class
When an object is instantiated from a class,
the constructor is automatically triggered
That's how you can think of it
So, here,
there's a hint in this line
When you initialize an Animal object,
Initialization simply means
assigning a value to a variable at the moment it is created
Looking at this example,
after using new followed by the class name,
you can see parentheses
The presence of parentheses indicates that a function is being called
Even though you don’t see it explicitly written in the code,
you’re still invoking a function
This function is referred to as the default constructor
A default function,
or a default constructor
This is how it looks like
Type public
And write in the class name
But this
does not specify a return type
Let's write this now
This is how a constructor function looks like
It is automatically called
when an object is created
There is
also a function automatically called when an object is destroyed,
called a destructor
Let's write this
A destructor is defined by prefixing
the class name with a tilde
It is automatically triggered when the object is no longer in use
and the memory is being reclaimed
However, in this example, an error occurs
because the destructor was defined with the public keyword
Destructors are not meant to be explicitly called by the programmer
but are instead invoked automatically by the system
Writing it
without the public keyword resolves this issue
But destructors are rarely used
because in C#, memory management
does not require creating
and intentionally destroying an object
It is handled by the garbage collector
or GC
The GC identifies objects that
are no longer in use
and automatically frees the memory they occupy
At this point, the destructor is called internally to clean up resources
Rather than relying on destructors,
if an object is no longer needed,
creating and invoking a dedicated function
to clean up and mark the object as unused
is often a clearer
and more efficient approach
But that's my personal opinion
Every programmer has a different method
So just know that this is one way
I’m not going to cover destructors in detail
This is what a constructor function looks like
So, in the constructor,
I’ll include what we did below like this
Then this becomes a reference to itself
I'll write it like this
But actually, if you look here, it’s written like this
If you write this in front,
this refers to this instance
So earlier, when I explained,
if in this function,
something like this was created,
this could be very confusing
and could cause issues
Because even though there’s no error,
if the field outside and the local variable have the same name,
in that case, let’s say here,
you want to assign a value to the name field
Then, if you check, you’ll see this happens
Since the name is the same,
you might intend to assign a value here,
but the name is the same
So in this function,
if you want to access the field outside and assign a value,
it becomes ambiguous
So, by writing this. in front,
you can access the field, not the local variable,
and assign a value to it
That’s why the this keyword exists
This is specifically used when
an object created from this class refers to itself
Let’s move on from this for now
This is how it is written
Now let’s try outputting it
When creating a class like this,
it’s better to stack functions neatly inside the class for processing
What I mean is, instead of creating an Animal object
and printing its name externally like this,
if you define a function inside the Animal class that prints its own name,
it becomes easier to access and use
So instead of doing it here,
I’ll create a print function here
public void print
and print name
And it will print the name
In this case, you can replace animal with this
And this can also be omitted here
If you don’t use this,
by default, it refers to this instance
Now, when you create an Animal object,
you can type animal. and see
the list of properties and functions that animal has
So you can say something like this
Hey Animal,
Animal, show me your properties or functions,
show me the function to print your name
This way, you can access it
And since this is a function,
you must include parentheses at the end
Since there are no parameters, you can finish it like this
When you run this, you’ll see that the name Animal is printed
Pretty simple
Class is created like this
So, in a way, we learned about variables and functions earlier, right?
Those are actually important components that make up a class
That’s why we covered them first,
and now, through classes, we can utilize them effectively
Now, let’s try inheritance
Earlier, I mentioned that there are four key elements in object-oriented programming
Among them, I’ll explain inheritance
To implement inheritance, let’s set Animal as the parent class
and create a class called Cat that inherits from it
Similarly, we write public,
followed by class Cat
To indicate inheritance, leave a space and add a colon,
and then write the name of the class you want to inherit from
Naturally,
you also define a scope using curly braces
Now, instead of creating an Animal instance,
let’s try creating a Cat instance
Since Cat inherits everything from Animal,
it has all the elements that Animal contains
When you create a variable in the parent format, like Animal,
what actually gets created through new
is an object in memory that adheres to the format
The format created in memory
takes the form of Cat
but transforms and is stored in the parent format
That’s the meaning here
This process involves type conversion
I will cover this again later
So, you can create it like this
This means that A cat is an animal
That's one way we can do this
However, you need to be careful about one thing
If you follow this method exactly
but reverse the order,
for example, making this Animal
and making this Cat,
then there will be a problem
The issue arises because, in memory, when a smaller object is created,
and you try to store it as a larger type,
this leads to inconsistencies
What I mean can be explained with a visual
Let’s say we have Animal and we have Cat
If Animal takes up this much space,
and Cat takes up this much space,
then if you create an object of type A,
representing all of what Animal is
Now, after creating A in the memory,
and then try to assign it to C,
like in this shape
But this doesn’t work
The reason is that the actual memory size for A is smaller,
but you’re trying to use it as a larger object,
which doesn’t make sense
In essence,
we have Animal
Animal
is Cat
That's what we're saying
Cat is smaller than an animal in terms of memory structure,
and there is an issue
An animal is not a cat, right?
Conversely,
let's say this is bigger here
Let's say we have Cat
Cat
is Animal
That's the sentence
This sentence is for this
The equal sign, yeah?
The assignment operator = first processes the right-hand side
So, a cat is an animal
becomes the valid expression
However, an animal is a cat
doesn’t make sense, right?
Animal is Cat
his illustrates the logical flow
So this is how it works
If we visualize this,
we have an Animal
and below it, a Cat that inherits from it
When we create a Cat object,
it is treated as an Animal object
This transition moves upwards,
and such a change is referred to as upcasting
Changing the type like this
is what we call type casting
Specifically, this is called type conversion
or type cast
Type cast
or type conversion
Among type conversions,
when a larger type moves to a smaller one,
this is upcasting
On the other hand,
when a smaller type transitions into a larger one,
this is referred to as downcasting
That's the term
Upcasting does not pose any issues
This is because a larger object
is adjusted to fit into a smaller type
But creating a smaller object and then expanding it into a larger object?
If the memory is already allocated for the smaller object,
arbitrarily attempting to expand it into a larger object would cause issues
So downcasting must be used carefully
When is downcasting allowed?
If you initially create a larger object,
convert it into a smaller object for some processing,
like when you convert a Cat object into an Animal object,
then convert that Animal back into a Cat object,
that's downcasting
This process is returning to the original size
Upcasting, on the other hand, happens naturally
So please remember these precautions
So, this causes an error
Doesn't work
So, this is called upcasting
When we talk about upcasting and downcasting, it can get very confusing
Even though I’ve drawn it out,
think of it as a relationship between classes.
After forming this relationship,
if the movement is upwards,
then that’s upcasting
If the movement is downwards,
then that’s downcasting
You can think of it this way
Once everything is set up this way,
all properties are inherited
If we run the program,
since everything is inherited,
the same output, Animal,
will be displayed like this
Now, let’s try something else
The Cat class has inherited everything from Animal
It's supposed to be Cat,
but since we used Animal here,
we're seeing Animal being printed
For instance, for the Cat class,
we want the name property to display Cat,
instead of Animal
Fo literally,
we want to rename it as Cat
How can we do that? Here's how
We declare
a public constructor
for the Cat class
And here,
the name, Cat
Let's change it like this
Now run it to see
this right here
See, Cat is indeed Animal
But now that we have an object, Cat,
this is being called like this
So the order would've been this first and then this
Let's try printing it
Let’s confirm this
In the Animal constructor,
I’ll add the line saying
Animal constructor is called
Here, Cat constructor is called
Let me write it out
So this is what happens
You’ll see the Animal constructor is called first,
and then the Cat constructor is called
So, both the parent and the child constructors are called
Like this
Constructors function in this way,
but there’s one more thing I’d like to try
What I’d like to do is create a specific functionality
I’m going to add a function called walking to the parent class
hen, I want to modify the walking function in the child class
to handle it differently
This is something you can do
So let’s add a function
to the Animal class
I’ll define it as public
We’ll call the function void Walk
The walk function will have a default behavior
When walking, I'll say, thump thump
So in the Animal class, walking will produce a thump thump sound
However, I want walking in the Cat class to behave differently
For now, let’s run the walk function in the Animal class and check the output
Animal
Although it’s technically an Animal,
it is actually a Cat object
Let’s call the walk function on the Cat object
This should call the parent class’s function
Let's change it like this
Let's delete this
This right here
is still in Animal
Although we’re calling it Animal, the actual data type is Cat
Let’s create the walk function
from the parent, Animal,
to its child, Cat, as well,
just like we did with the constructor earlier
For example, how does a cat walk?
A cat probably walks quietly or softly, right?
So let’s have the walk function output tiptoeing
The walk function in the parent class produces a thump thump sound,
while the walk function in the Cat class outputs tiptoeing
Now see,
when you call the walk function
on a Cat object, what is being called
is the tiptoeing we added
However, we don’t always use it this way
Instead of directly calling the walk function on the Cat class,
we often keep the variable in the parent class format
and the object in the child class format
The benefit of this approach is this
For instance, if you create a Dog class later,
even with that,
you won’t need to modify this part of the code
You just need to change this part to dog
For example, copy this as is,
then modify it like this, replacing it with dog
Call this Puppy
Dog
For the walk function, let’s say it walks with a da-da-da-da sound
Now that we’ve done this,
the advantage here is this
even if we change things like this, there are no issues
You don’t need to modify this part at all
Just change the object being created,
and if you run it like this, it switches cleanly to the Puppy
Now, if you switch back to cat,
you’ll see that everything outputs as thump thump
This happens because, as I mentioned earlier,
when I created this,
if I call one cat and the other puppy,
and add outputs for the puppy too
If I set this up to print, it’ll behave like this
Thump thump here,
and here's Pupy
Both the cat and the dog will output thump thump
What we want is not thump thump,
but for each to call its own walk function
This isn’t happening because,
in programming, there’s a rule that when calling functions or methods,
the function being called doesn’t belong to the created object
It belongs
to the type of the variable on the left side
So, it’s the function of the variable’s data type that gets called
For the walk function, this means
it calls Animal’s walk
The same applies to the print function
What we want, though, is, let's keep this here
When the object changes,
call Cat’s walk for cats
and Dog’s walk for Puppy
It should follow the type of the created object
There’s a way to achieve this, which is
to override the function
Currently, the function hasn’t been properly overridden
There’s a concept of overriding a function’s behavior
When we have functions
with the same name but different parameters,
we call it overloading
which is in overlap
Functions with the same name
but different argument lists
are selected based on the parameters passed to them
Automatically calling the appropriate function
based on the given parameters, that's overloading
And we also have
a concept called overriding
This means
we can override a parent class’s function
in the child class
To do this,
we use the override keyword
Here’s how it looks
We add the override keyword to the child class’s function,
and virtual to the parent
By making it virtual,
the child class can override it
So, this is how you write it
So what happens is this
Cat's Walk,
though we just see Animal here,
let's finish Puppy too
Override here too
Let's write this and run it
It changed
The cat outputs tiptoeing, and the dog outputs da-da-da-da
So, by using virtual and override,
you ensure
that the function corresponds
not to the data type of the variable, but to the object’s type
This is very important
You should remember that
Now, let’s try encapsulation
Earlier, I mentioned
that we can hide certain functionalities
I’ll try implementing this in the Animal class
In Animal,
instead of the name,
I’ll define an age
So, this time, instead of public,
I’ll make it private int age
Then, in the Animal class,
I’ll set the age
to 10
Let's say this
To display this, we need a function to output the value
Since it’s private, you can’t access it directly from outside
For example, if I create an Animal instance
and try to access the age field,
it won’t appear in the list of accessible members
To explain, let's try Animal here
This here allows you to split the screen
Like this
Here it is
Just pull it up like this
We have the variable age for Animal
Let's create it here
Let's say we have it like this
Now in Animal,
click on Animal
We have name
We have name,
but we don't have age
It's private, so it's not open here
Let's switch this to public
We have age
Switch it back to private,
press ctrl and space bar to see it again
Now the age is gone
So whether to keep it
public or private
is up to the developer
So since age is private now,
we may want to print this
So let's add another function here
Below PrintName,
make a function called PrintAge
Copy it
and call age
Like so
Here, age
PrintAge
Now it calls
Now, 10
Let's delete this part with //
Let's remove all these
Let'a call PrintAge in here
Now it provides 10
This is how certain information can be private
If it's not private but protected,
so now in the parent,
let's see it here
The parent can be private too
So the child who inherits this can't access it
Se, I can't try age under name equals Cat
We see no age
If we change this to protected,
like this,
in Cat, type age and you see it
like this
Let's say 20 for Cat and 30 for Puppy
For this,
let's do PrintAge for both
So Animal, PrintAge
Let's do PrintAge for both cat and dog
Now we see 10, 20, 30
it tracks all of the ages
So using private an protected,
we allow certain accessibility
to the things to tailor our needs
Lastly, let’s talk about polymorphism
Actually, what we’ve been discussing so far aligns with the topic of polymorphism
Polymorphism is essentially about how we automatically typecast objects,
changing their type format, as we’ve seen
Like this
What we can see here
is something like this
When I first talked about polymorphism,
I said this in my diagram
There is a parent class A and a child class B,
A looking this big and B this big
in an inheritance
Then A belongs in here
Suppose A has a certain set of variables
and to B,
I created another variable or function
Let's create a function called A
So when the object is type A,
we can create it as type B
and have it like this
But in the end,
if it expresses this as a
a.AAA does not exist
It does not
Because, this A is in fact B in the memory,
shortened to contain the form of A
So this is the form it has
So there's no function called AAA
It should be B so that it allows access to this function of this member
So that's what polymorphism does
Let's demonstrate it
Here we have our Puppy part
In here,
I'll create a variable called type
Let's create a function called PrintType
Public Void PrintType
Let's print anything here
Let's print
I just made it for Puppy,
in Dog
So let's just remove all these
and just look at this
Let's have this Dog an object,
now Animal,
like this
When we do type casting,
this is casted implicitly
It can either be done implicitly or explicitly
Explicit typecasting
means we write Animal here
So in C#, when we do type casting,
using parentheses is the old way of doing it
But in C#, we just write it out as this, as Animal
That's when we use as
If we type cast this object as Animal,
we aren't sure
whether it inherited Animal or not
We need to read the code to make sure
When the compiler is performing its tasks,
it needs to verify
and check if the type relationship,
the inheritance hierarchy is valid
If so, it will reduce the object to the Animal type and return it accordingly
If not,
if it is not in inheritance
but still tries to type cast, it will say null
In fact, for classes,
like we made,
we said new to our class, but we can also ad null
Null simply means empty
It has no existence
It has its container, but no memory is assigned
Or no value is assigned
That's why it returns null
If this is not inheritance,
it is better to use the keyword
of as when we type cast it
Let's change it
I changed the object Dog to Animal
Then, in Dog,
there is a function we made, PrintType
Right here
However, I didn’t reassign the dog object to a new value
Instead, I simply type casted the existing dog object to a different type
This process is called casting
We've done the casting
After casting, if I attempt to call the printType function, it won’t work
It doesn't exist
There is no function like that
The reason is that the cast changes the object’s type,
and functions specific to the original type,
like printType, are no longer accessible
That's what polymorphism does
Let’s summarize what we learned in this lesson
Understanding Object-Oriented Programming and Classes OOP: Creating everything as an object and programming through interactions between objects
Classes: user-defined data types with attributes and functions Variables: written in noun, functions: written in verb Method: function Field: variable
Object: Variable created using a class Classes have an inside and outside area Access modifiers: public, private, protected
Local variables inside functions are accessed first
Constructor, Inheritance, Encapsulation, and Polymorphism Constructor: Class: public class Animal Constructor: public Animal() Destructor: ~Animal()
Inheritance Classes form relationships where child classes represent larger, more specific forms than parent classes
Abstraction Simplifies complexity by implementing only the necessary attributes in a class
Encapsulation Prevents access from external classes, often achieved through encapsulation Access modifiers: public, private, protected
Polymorphism Type casting allows objects to change forms through type transformation.
Possible only within inheritance relationships, enabling objects to take on multiple forms Objects can only access those with the right type