1. | What is an instance variable? |
|
2. | How do you determine the size of a class? |
|
3. | Explain the steps necessary to create an instance of a class. |
|
4. | How do you declare an instance variable? |
|
5. | What is a data type? |
|
6. | Explain the parts of a method definition. |
|
7. | What is the difference between an argument list and a parameter list? |
|
8. | Explain the steps for calling a member method. |
|
9. | What is a constructor and how do you define one? |
|
10. | How do you access an instance variable from within your program? |
|
Answers
1. | An instance variable is an attribute of a class. |
2. | You determine the class size by adding the size of all its attributes. |
3. | You declare an instance of a class by first reserving memory for the class using the new operator followed by the constructor of the class ( new RegistrationForm() ). Next, declare a reference to the class and give that reference a name ( RegistrationForm myRegistrationform ). Finally, assign a reference to the memory reserved for the class to the reference using an assignment statement. |
4. | An instance variable is declared by specifying the data type of the variable, followed by the variable name, and ending with a semicolon within the body of a class definition. |
5. | A data type is a keyword that tells the computer the kind of data you want to store in a memory location. |
6. | A method definition consists of the name of a method, an argument list (if any), the data type of the value returned by the method, and the method body. |
7. | Although some programmers consider an argument list and a parameter list to be the same thing, other programmers consider a parameter list to be values passed to a method when the method is called, and they consider an argument list to be values defined within the method definition that receive values passed to the method. |
8. | A member method is called by first declaring an instance of a class and then using the name of the instance followed by the dot operator and the name of the method ” myInstance.myMethod() , for example. |
9. | A constructor is a method of a class that is called automatically when an instance of a class is declared. A constructor is defined in the class and must have the same name as the class name. A class can have multiple constructors, each with a different argument list. The argument list is traditionally used with the constructor to initialize instance variables of the class. |
10. | An instance variable is accessed by first declaring an instance of a class and then using the name of the instance followed by the dot operator and the name of the variable ” myInstance.myVariable , for example. |