MODULE 2 (Week 3): Assessors, Mutators and Constructors Flashcards
To create an instance of a class:
Supply a type and an identifier
Allocate computer memory for the object
Use the new operator
The name for a memory address where the object is held
Reference to the object
A method that creates and
initializes class objects
Constructor method
The name of the constructor should always be what?
The name of the class whose objects it constructs
After an object is instantiated,
its methods can be accessed
using:
The object’s identifier
A dot
A method call
Data fields are usually private; The client application accesses them only through:
Public interfaces
Controls the data values used to set a variable
Set method
Controls how a value is retrieved
Get method
A type of constructor that requires no arguments and is created automatically by a Java compiler whenever you do not write a constructor
Default constructors
What are the initial default values that a default constructor provides to an object’s data fields
Numerical field - set to 0
Character fields - set to Unicode \u0000
Boolean fields - set to false
Nonprimitive object fields - set to null
A construction method:
Must have the same name as the class it constructs
Cannot have a return type
Has a public access modifier
Classes that you create become data types and are often referred to as:
Abstract data types (ADTs)
Data types not built into the language
Programmer-defined data type
How to declare an object from one of your classes?
Provide the type and identifier