CSE 1321 Exam 3 Flashcards
*Represent the concept of things in the real world (example: Dogs)
Follow the template:
- name
- variables (aka attributes)
- functions (aka methods, behaviors, method functions)
Classes
These are what the object IS made up of
Variables relation to objects
These are what the object CAN DO
Functions relation to objects
What would the smallest class look like?
class ClassName{
}
Notice that there is no MAIN here
*Has attributes
*Has a constructor whish is used to intialize attributes
*Has other methods
*Template for creating objects
*Creates a new complex data type
EXAMPLE: blueprints for a house
Class
*A class is basically just you creating a data type and it doesn’t need to run any code unless you tell it to.
*Is an instance of a class
*has a state(variables) that is independent from others
EXAMPLE: your specific house with specific colors and finishes
Object
What is the purpose of a constructor
to initialize objects
Can you have multiple constructors?
Yes; this is known as constructor overloading
What happens if you don’t create a constructor
an “invisible” default constructor is made automatically. Otherwise you wouldn’t be able to create objects.
When creating a constructor, the parameters should be only what we know (true/false)
true
If an object’s state is constant, we should set it as a parameter of the constructor (true/false)
false
(Java) What is the purpose of using “this. “?
“this. “ tells the program that the variable after the dot operator is a variable inside that class. It is used commonly with constructors and methods.
Constructor names must match the name of the class they are in. (true/false)
True
What is another word for SETTER?
Modifier or Mutator
(Note that the public and private keywords are known as ACCESS modifiers)
What is another word for GETTER?
Accessor
What is the purpose of GETTERS and SETTERS?
They help with encapsulation which increases protection. By making variables private and creating GETTERS and SETTERS, you limit the ways in which someone can alter the private data.
Is there a way to access private variables from outside a class?
Yes, if the private variables are in a class that also has non-private GETTER and SETTER methods for the private variables, you can access the variables from anywhere.
When variables are private, where can you directly access them from?
Only the class they are inside will have access to the variable. Same goes for methods.
When variables are public, where can you access them from?
Any class can refer to the variable. Same goes for methods.
You can create multiple classes in one file. How many of these classes can be listed as PUBLIC?
Only one can be listed as public, and it has to match the file name.
All other classes will just be instantiated as class.
can a SETTER method return more than one value?
SETTER methods don’t return value, they only set them, so the return type is VOID
do SETTER methods need parameters?
Yes. The parameters will be whatever value you are setting. If you are setting the name of a dog to Sparky, your SETTER parameter will be a string.
in the context of this class, do GETTER methods typically have parameters?
no. the purpose of the GETTER method is only to access a private value and return that value.
An object’s method is called by
writing the objects name followed by the dot operator and the method name