Card Set Information
diane cs140 powerpoint 7
The attributes of an object (that describe its state) are called ____________.
In addition to attributes, classes can have _____________.
What is the standard way of describing a class?
A UML diagram.
In the cookie cutter/cookie analogy, the class is the _________________ while the object is the ____________.
cookie cutter (structure), cookie (instance)
How many classes should be in a .java file?
Can classes compile without a program?
What is the minimum number of classes that should be in a program?
1 - the file that holds the main method is also in a class
An object is an ______________ of a class.
How should you decide if a variable or a method that is part of a class should be public or private?
Variables should be private. Methods should be private unless there is a compelling reason to make them public.
What is the syntax for declaring a new instance of a class (an object)?
className objectName = new className();
When a new object is created, what happens in Java?
The memory is allocated and the memory address of the object is assigned to the variable.
What does the modifier "public" mean?
It means that any other class can directly use or access the class, method, or instance variable by name.
What does the modifier "private" mean?
It means that no other class can directly use or access the class, method, or instance variable by name, but they can be accessed within the parent class.
What can you do to make variables retreivable if they are private and you need to know access them outside of the parent class?
You can make helper methods that return the value of private variables.
Do NOT declare ___________ classes private. They will be unusable, as no one will be able to access them.
What is a constructor?
A constructor is a special type of method that is invoked when you create an object of a class with new.
What does a constructor do?
A constructor creates and initializes a new object whose address is then given back to the object.
Constructors have ________ return type/value.
Constructors really return the ____________ of the newly created object.
Constructors must have the same ________ as the name of the class.
When a constructor is called, Java __________________ to all instance variables.
assigns default values
If you don't create a constructor, ____________________________.
Java creates one for you
If you create even one custom constructor, Java __________________________.
won't do it for you anymore, and you must create a "default" type constructor
Always make your own _______________ constructor (even if you don't plan to use it).
What is this? What does it do?
"this" is a reserved word in Java. Inside the definition of a method, it points to the object receiving the method call. It is usually optional, but good practice to use it.
Constructors can/can not call other constructors.
Can. It must be the first action taken by the constructor, though.