Explain dot operators in simple words | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Explain dot operators in simple words

With example

11th Jul 2021, 5:46 AM
๐“๐“ท๐“ผ๐“ฑ๐“ฒ๐“ด๐“ช (Anshika)
๐“๐“ท๐“ผ๐“ฑ๐“ฒ๐“ด๐“ช (Anshika) - avatar
2 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(); } }
19th Oct 2021, 8:39 AM
Vaibhav
Vaibhav - avatar
+ 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
11th Jul 2021, 5:51 AM
Abhiyantฤ
Abhiyantฤ - avatar