click below
click below
Normal Size Small Size show me how
Objects and Classes
ENGR 131 test review
| Question | Answer |
|---|---|
| Constructs that define objects of the same type | Classes |
| Objects have both a ____ and a _____. | State (defines object), behavior (defines what the object does). |
| Special kind of methods that are invoked to construct objects. | Constructors |
| Constructor with no parameters is called a | No-arg constructor |
| Return type of constructors? | None; constructors do not have a return type, not even void. |
| Role of constructor | Initialize objects |
| No-arg constructor with an empty body that's automatically provided if no constructors are explicitly declared in the class . | Default Constructor |
| If a data field of a reference type does not reference any object, it has this value. | Null |
| Default value for a reference type | Null |
| Default value for a numeric type | 0 |
| Default value for a boolean type | False |
| Default Value for a char type | '\u0000' |
| Default value for a local variable inside a method | None; Java doesn't assign one. |
| Object that is no longer referenced and is cleaned up by JVM | Garbage |
| How to access date class | java.util.date, use .toString method to return the date and time as a string. |
| How to use Random class | java.util.Random Random random1 = new Random(3) where 3 is the seed random1.nextInt(1000) generates a random number up to 1000 |
| Variables that belong to a specific instance | Instance variables |
| Methods invoked by an instance of the class | Instance methods |
| Variables shared by all instances of the class | Static variables |
| Methods not tied to a specific object | Static methods |
| Final variables shared by all the instances of the class | Static constants |
| Class, data, or method is visible to any class in any package | public |
| The data or methods can be accessed only by the declaring class. | Private |