+ 4
Explain dot operators in simple words
With example
3 Answers
+ 9
The dot operator, also known as separator or period used to separate a variable or method from a reference variable. Only static variables or methods can be accessed using class name.
public class Sample {
void display() {
double d = 20.3;
int i = (int)d;
System.out.println(i);
}
public static void main(String args[]) {
Sample s = new Sample();
s.display();
}
}
+ 6
I think this is the easy explanation, given by tutorialpoint
The (.) operator is also known as member operator it is used to access the member of a package or a class.
Example -
public class Sample {
void display() {
double d = 20.3;
int i = (int)d;
System.out.println(i);
}
public static void main(String args[]) {
Sample s = new Sample();
s.display();
}
}
Output - 20