How to call a method with out object reference.
I tried this calling this by
Byte().add();
I am getting an error
How to call a method with out object reference.
I tried this calling this by
Byte().add();
I am getting an error
You cannot call an instance method without an object reference. The instance method belongs, by definition, to an instance of the object's class.
If the method were static
, then you could call it using the name of the class. Static methods belong to the class definition itself, so no instance is required.
Also, your syntax is off, it's not
Byte().add();
It's
Byte.add(); //static method
or
new Byte().add() //instance method or static method, either can be called this way.
You cant call an instance method without an Object reference
. But if the method is static
you can call it with class.
If you want to call a method without making an instance make that method static
. Please learn difference between static and instance method