1/25
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Constructor
A special block of code in OOP that initializes the instance variables of an object.
Instance Variables
Attributes that hold the state of an object.
Name Match
Rule stating that a constructor's name must match the class name.
No Return Type
Constructors do not have a return type, not even void.
Automatic Call
Constructors are called automatically when using the new keyword.
No-Argument Constructor
A constructor that takes no parameters and sets instance variables to default values.
Parameterized Constructor
A constructor that accepts parameters to set instance variables to specific values.
Constructor Overloading
Having more than one constructor in a class with different parameter lists.
Default Constructor Trap
If a class has any constructor, the default no-argument constructor is no longer provided by Java.
Method Header
Defines how code interacts with the method consisting of the access specifier, return type, method name, and parameter list.
Access Specifier
Determines the visibility of a method, usually public or private.
Return Type
Indicates the type of data returned by a method.
Method Name
Follows camelCase convention and describes the action of the method.
Parameter List
Variables listed in parentheses that act as local variables within the method.
Method Signature
Consists of the method name and parameter list only, excluding return type.
return Statement
Used in methods with a return type to return a value and halt method execution.
Accessor Methods
Public methods that allow controlled access to private instance variables.
Encapsulation
The principle of keeping instance variables private and exposing them via public methods.
Pass-by-Value
When parameters are passed to a method, a copy of the value is passed.
Primitives
Basic data types like int, double, etc., where a copy of the value is passed.
Objects
References to objects are passed by value, allowing modifications to the object's state.
Common Pitfall: void Constructor
Adding void to a constructor declaration makes it a method instead.
Shadowing Variables
Naming a parameter the same as an instance variable without using 'this' to differentiate.
Unreachable Code
Code placed after a return statement which can never be executed.
Header vs. Call Confusion
Confusing method header with method call syntax.
Method Call Example
Correctly calling a method without type declarations like myObject.add(5, 10).