0 votes
1 view
in Java by (10.2k points)
What does .class mean in Java? For example, if I created a class called Print. What does Print.class return?

1 Answer

0 votes
by (46.1k points)

When you write .class after a class name, it references the class literal - java.lang.Class object that represents information about given class.

For example, if your class is Print, then Print.class is an object that represents the class Print on runtime. It is the same object that is returned by the getClass() method of any (direct) instance of Print.

Print myPrint = new Print();

System.out.println(Print.class.getName());

System.out.println(myPrint.getClass().getName());

Related questions

0 votes
1 answer
0 votes
1 answer
asked Dec 2, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...