What is the answer to each of the following?
1. What is a field?
2. What is a constructor?
3. What does override mean?
4. How do you specify the parent class of the class you are declaring?
5. If you don’t specify a parent class is there still a parent class?
6. How do you overload a constructor?
7. What is the difference between override and overload?
8. How do you create an array?
9. How do you access elements of an array?
10. How do you initialize the elements of an array?
11. What is a Javadoc comment?
12. Can objects of a different class (in a different file) directly access private fields?
13. Can objects of a different class (in a different file) directly access public fields?
14. What is an accessor method?
15. What is a modifier method?
16. What does encapsulate mean?
17. What does super.method() do?
18. What does super() do?
1. Fields are the data that each object of a class keeps track of. Simple data represented by numbers or Strings are usually fields.
2. A constructor is called each time a new object is created. It sets-up the object which usually means initializing the fields.
3. When a child class overrides a parent’s method it means the child’s method is called instead of the parent’s method.
4. You specify the parent class by using extends followed by the name of the parent class.
5. Yes, the parent class will be Object.
6. You create another constructor that has a different parameter list.
7. Overload means two methods in the same class have the same name but different parameter lists. Override means a child has a method with the same name and parameter list as a parent method.
8. Use new type[size] to create an array. The type can be any primitive type or the name of a class.
9. Use var = arrayName[index] to get the value at the index in the array. Use arrayName[index] = var; to set the value at the index in the array to the value in var.
10. You can use type[] var = value1,value2,value3 to initialize an array of three items to the values in value1, value2, and value3.
11. A comment that is used to create HTML documentation for the class using the javadoc utility from Sun.
12. No, private fields can only be directly accessed by code in the same file as the class.
13. Yes, public fields can be directly accessed using dot notation by code in any class.
14. This is a method that returns the value of a field.
15. This is a method that sets the value of a field.
16. To put one thing inside another. We say that an object encapsulates the fields in the object. It also should protect the fields by making them private.
17. It looks for the method in the parent class of the class that this code is in.
18. It invokes the constructor in the parent class that takes no parameters.
You might also like to view...
The Cloud is a(n) ________ used to store and work with files and programs stored in a central location
A) the Office Clipboard B) Access C) Internet technology D) an Office Add-in
You can adjust the widths of columns using the CSS ____ property of the
A. units B. length C. width D. size