You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Java, <term>constructors</term> have the same name as the class and are declared public.
221
221
They are declared without a return type.
222
222
So any method that is named the same as the class and has no return type is a constructor.
223
-
Our constructor will take two parameters: the numerator and the denominator.
223
+
Our constructor will take two parameters: the numerator and the denominator. <xrefref="java-fraction-constructor"text="type-global"/> shows the constructor for the <c>Fraction</c> class.
@@ -241,18 +242,19 @@ public Fraction(Integer top, Integer bottom) {
241
242
This allows the Java compiler to do the work of dereferencing the current Java object.
242
243
Java does provide a special variable called <c>this</c> that works like the <c>self</c> variable.
243
244
In Java, <c>this</c> is typically only used when it is needed to differentiate between a parameter or local variable and an instance variable.
244
-
For example this alternate definition of the the Fraction constructor uses <c>this</c> to differentiate between parameters and instance variables.
245
+
For example,<xrefref="java-fraction-constructor"text="type-global"/> shows an alternate definition of the the Fraction constructor that uses <c>this</c> to differentiate between parameters and instance variables.
0 commit comments