• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One doubt

 
Rajeswari Kumar
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a question from whizlabs.

class AutoBox2 {
public static void main(String []ar) {
Float F=new Float(9.0);
float f=(float)9.0;
System.out.println(f.equals(F));
}
}
When I am trying to compile the program, following error has come
AutoBox2.java:6: float cannot be dereferenced
System.out.println(f.equals(F));
^
1 error
What is called dereferencing. But if it is given as
System.out.println(F.equals(f));
code compiles fine. Please explain me.
 
anil kumar
Ranch Hand
Posts: 447
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
kumar

Here f is primitive.How can you call a method on primitive variable ?

Thanks

Anil Kumar
 
Rajeswari Kumar
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Yes. Thanku. It didn't strike for me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic