click below
click below
Normal Size Small Size show me how
SCJA-drills-chap05
Question | Answer |
---|---|
Define the concept of variable scope. | A variable’s scope defines what parts of the code have access to that variable. |
Describe the scope of instance variables. | An instance variable is declared in the class, not inside of any method. It is in scope for the entire method and remains in memory for as long as the instance of the class it was declared in remains in memory. |
Describe the scope of method parameters. | Method parameters are declared in the method declaration; they are in scope for the entire method. |
Where in the code are local variables declared? What is their scope? | Local variables may be declared anywhere in code. They remain in scope as long as the execution of code does not leave the block they were declared in. |
Which entity is passed to a method for input? | Code that invokes a method may pass arguments to it for input. |
How are primitive passed to methods? | Primitives are passed by value. |
How are objects passed to methods? | Objects are passed by reference. |
What may a method return? | Methods may return one variable or none at all. It can be a primitive or an object. |
What does a method declaration include regarding possible return entities? | A method must declare the data type of any variable it returns. |
What happens if a method does not return any data? | If a method does not return any data, it must use void as its return type. |