Objects, Classes and Constructors Flashcards
How many classes in a file can be a public class?
In Java, only one class per file can be public.
If a class is declared public, the file name must match the class name, with the extension .java. For example, if you have a public class named MyClass, the file containing the class must be named MyClass.java.
Constructors are a special kind of method. What are their 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.)
___ represents an entity in the real world that can be distinctly identified
A class
__ is a construct that defines objects of the same type
A class
An object is an instance of a __
class
__ is invoked to create an object
A constructor
Given the declaration Circle x = new Circle(), which of the following statement is most accurate
x contains an int value
x contains an object of the Circle type
x contains a reference to a Circle object
you can assign an int value to x
x contains a reference to a Circle object
The default value for data field of a boolean type, numeric type, object type is ____, _____, ______ respectively
false, 0, null
what is the syntax for creating an object (workerOne) from the class Workers using a default constructor
Workers workerOne = new Workers();
what are the 3 types of constructors?
Default Constructor
No-Arg (no-argument) Constructor
Parameterized Constructor
what is the syntax for creating an object (workerOne) from the class Workers using a parameterized constructor which needs name (“Bob”) and age (“35”) arguments
Workers workerOne = new Workers(“Bob”, 35);
what does overloading mean?
That you can have more than one method (including constructors) with the same name as long as the method is unique.
what are the criteria that can make a method(including constructors) unique?
Different number or order of arguments/parameters
AND / OR
Different parameter/arguments types
What is dot notation used for?
to access the instance data and methods of an object once it is created. commonly:
Update a class member value.
Access a class member value.
Call a method.
what are the members of a class?
variables (aka: attributes or fields),
methods,
constructors.