Final Exam Flashcards
Definition of a class…
A class is the template/blueprint from which individual objects are created; it describes the behaviors/states that object of its type support.
Collection of data members and methods
Definition of an object…
Objects have states and behaviors; they are an instance of a class.
Example of an object.
Dog:
states - color, name, breed
behaviors - wagging, barking, eating
Definition of a method…
Collection of statements that are grouped together to perform an operation.
What is a modifier…
Defines the access type of the method and it is optional to use.
What is the purpose of a constructor?
Initializes an object when it is created; create an instance of a class!
Can take only access modifiers – cannot be abstract, final, native, static, or synchronized.
Do not have a return type.
Have same name as their class name.
Uppercase.
Usually a noun.
When do you use a constructor?
To give initial values to the instance variables defined by the class, or to perform any other startup procedures required to create a fully formed object.
Does Java have a default constructor?
Java automatically provides a default constructor that initializes all member variables to zero.
What is an instance member?
Memory space is created each and every time whenever an object is created.
Meant for storing specific values.
What is a static member?
Memory space is created only once – when the class is loaded in the main memory; no objects are created.
Meant for storing common values.
What are the two types of data members?
Static
Instance (aka. non-static)
How is an instance data member accessed?
Object name.
How is a static data member accessed?
Class name.
What is the purpose of a method?
To execute code.
Give an example of a constructor for the class: Platypus
Platypus p1 = new Platypus();
Describe what a super class does…
Calls the overridden method of the superclass.
What class does Java extend when you do not explicitly extend a class?
Object class.