Module 01-09 Introduction to Classes Flashcards
What are classes?
Classes serve as blueprints that indicate what variables and methods an object has.
Many individual objects with different variables and methods can be made from the same class.
Variables and properties represent an object’s…
State
Methods indicate an object’s
Behaviors
How would you declare an instance of class Clock called clock?
Clock clock = new Clock();
Private and Public are called…
Access modifiers.
They control visibility to methods and properties to the rest of your program.
A derived property…
Lets you generate a value by relying on the other properties within the class.
A derived property is a getter that, instead of returning a member variable, returns a calculation taken from member variables. If we have firstName and lastName, we don’t need to also store fullName, we can derive it from what we already have.
Methods are for when you need and object to…
do something! (perform a behavior)
What does Encapsulation do?
Encapsulation lets you restrict access to the internal mechanism of how the class works by hiding or protecting its variables.
It’s the first pillar of object-oriented programming.
What do methods with “void” method signatures return?
Nothing!
What is a constructor?
A constructor is a special method that runs every time a new object is instantiated. It allows for the object to be initialized with a starting state.
It doesn’t return anything.
It must have the same name as the Class.
It can have arguments that set the value of member variables, like a Setter.
It can be Overloaded to provide multiple ways to instantiate the object.
If no constructor is present, then Java provides a default constructor, which has no arguments.
Three Rules of an Overloaded Method
- Overloaded methods must have the same name.
- Overloaded methods must have the same return type (does not apply to constructors).
- Overloaded methods must differ in the number of parameters and/or parameter types.
What is Inheritance?
Inheritance is the practice of creating a hierarchy for classes in which descendants obtain the attributes and behaviors from other classes.
What is Polymorphism?
Polymorphism is the ability for our code to take on different forms. In other words, we have the ability to treat classes generically and get specific results.
All Reference Types are defined by a…
Class
All Classes are defined by a…
Data Type