Classes and Objects (Head First Java - Ch. 2, 4, 10) Flashcards
Head First Java - Ch. 2, 4, 10
Whats a primitive data type? give examples.
not considered objects or raw values and are stored directly on STACK.
byte, int, float, char, long, short, double, boolean
How many classes in a file can be a public class?
Only one.
Constructors are a special kind of method. What are three peculiarities?
A constructor must have the same name as the class itself.
Constructors do not have a return type, not even void.
Constructors are invoked using the new operator when an object is created. Constructors play the role of initializing objects.
__ is a construct that defines objects of the same type
A class
An object is an instance of a __
a class
Which operator is used to create an object?
“new” operator
You need ____ classes to create and use an object? Why?
two classes. One for the type of object you want to use. One to put your main() method in (tester class)
What is the point of a tester class?
To create and access objects of your new class type. It will use the dot operator to access the methods and variables of the new objects
How do we declare an object in the tester class (an instance of a class)? How do we access the variables method?
- [Class name] [variable] = new Class name
- [variable].[method]
method is made in other class
What’s a parameter?
is a local variable, with a type and name, and can be used inside of the body of the method
What is a return type?
the expected data type in return value for a method. A method could also have a void return type.
Can a variables value change once passed into a method?
No - the value can only be changed within the method
Is it required to have a return value for a non-void return type?
No it’s not require if we are just calling the method for the work it does inside the method
What’s a setter method?
A method used just to set the value of an instance variable - it will have a void return type
What’s a getter method?
A method used to return the value of an instance variable - it will have a matching return type