can someone explain to me what does the dot mean and what w
can someone explain to me what does the dot mean ? and what would be the output and explain it?
import java.io.*;
public class Green {
private int a;
private int b;
public Green(int aa,int bb)
{
a=aa; b=bb; }
public void equals(Green c)
{ this.a=c.a;this.b=c.b;}
public void fn(Green c)
{ this.a=3*c.b-c.a;
this.b=2*c.a-this.b;}
public void gg()
{ this.b=this.b-1;
this.a=this.b-2; }
public static void main(String args[]) {
Green x=new Green(2,2);
Green y=new Green(2,1);
Green z=new Green(1,4);
int xx=1,yy=2,zz=3;
x.fn(y);
z.gg();
System.out.println(\" Value of x.a is = \" +x.a);
System.out.println(\" Value of x.b is = \" +x.b);
System.out.println(\" Value of z.b is = \" +z.b);
}
}
Solution
Dot(.) is a operator used to access instance variable of particular class.
this.a
this variable referes the instance variable a.
To call methods and objects in Java Dot(.) operator is used.
z.gg();
where z is the object and gg() is the function called by using Dot operator
Output:
Value of x.a is = 1
Value of x.b is = 2
Value of z.b is = 3
When the function x.fn(y); called the variable a, b, and c takes the input as a =2, B=1, C=1.
When the function z.gg(); called the variable a and b takes the input as a =1, B=4.
