Podcast
Questions and Answers
What does the void keyword denote in a method?
What does the void keyword denote in a method?
What is the difference between a parameter and an argument in a method?
What is the difference between a parameter and an argument in a method?
Why must the data type of the return value match the declared return type in a method?
Why must the data type of the return value match the declared return type in a method?
What do instance variables refer to in Java?
What do instance variables refer to in Java?
Signup and view all the answers
What purpose does 'this' keyword serve in Java?
What purpose does 'this' keyword serve in Java?
Signup and view all the answers
What is the main purpose of a mutator method in Java?
What is the main purpose of a mutator method in Java?
Signup and view all the answers
How does a private method in Java differ from a public method?
How does a private method in Java differ from a public method?
Signup and view all the answers
What is encapsulation in object-oriented programming?
What is encapsulation in object-oriented programming?
Signup and view all the answers
In Java, what does a UML Class Diagram display?
In Java, what does a UML Class Diagram display?
Signup and view all the answers
How are references handled in Java with respect to objects?
How are references handled in Java with respect to objects?
Signup and view all the answers
Study Notes
Classes and Methods
- The
void
keyword indicates that a method does not return a value. - A parameter is a list of variables in a method declaration, while an argument is the actual value passed when the method is invoked.
- The data type of the return value must match the declared return type.
Instance Variables and Local Variables
- Instance variables are variables declared outside a method, constructor, or block.
- Local variables are variables declared within a method definition and are only visible to that method.
The this
Keyword
- The
this
keyword represents the object's name receiving the method call within a method definition.
Information Hiding and Encapsulation
- Information hiding is a mechanism for restricting access to some of an object's components.
- Advantages of information hiding include:
- Making components easier to understand and use
- Simplifying modification and repair
- Facilitating re-use
- If an instance variable is public, there are no restrictions on where its name can be used.
- If an instance variable is private, its name cannot be used to access it outside of the class definition.
- Accessor methods are public methods that return data from private instance variables.
- Mutator methods are public methods that change the data stored in one or more private instance variables.
Encapsulation
- Encapsulation is the process of combining data and actions into a single item.
- It groups instance variables and methods into a class and hides implementation details.
UML Class Diagram
- The UML Class Diagram describes the structure of a class by displaying the class name, variables, and methods.
Objects and References
- A variable of a class type contains the memory address of the object named by the variable, rather than the object itself.
- The address of the object's memory location is called a reference to the object.
- Class types are reference types whose variables hold references or memory addresses.
- Use the
equals()
method for comparison, instead of==
.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge on class methods and definitions in STI IT1712! Learn about the void keyword, parameters versus arguments, return types, and instance variables.