+ 1
Variable and Object
What is the difference between variable and object in Java.
7 Answers
+ 1
Myclass var1; //in method
var1.do_something(); // error
var1 is empty, even not null there. It is not possible used it without value assignment. There's no way to call the method of the nothing.
+ 15
In simple words
Veriable
It is a container for your value.
Example :
int a = 10;
int // is a identifier
a // is a variable
10 // is a value
Object
Suppose you are a object and and you have some function like walking taking hearing seeing emotions ext.
In final
there is big difference of veriable and object. i think you will catch what i mean.
+ 1
~ swim ~
I think there is no concept of pointer in java.
That's why it is still showing error in these lines
MyClass *obj = new MyClass() ;
obj->do_something() ;
+ 1
~ swim ~
Ok.
please tell me,
what does var do?
+ 1
~ swim ~ thanks đ
+ 1
Ujjawal Dubey you r trying to access func with variable which is not possible I think causing to give error. Objects can invoke func not varibles. I think if not wrong.
0
@~swim~
class Myclass{
----------;
void do_somthing()
{
}
}
Myclass var; // variable of type Myclass
Myclass obj = new Myclass(); // object of Myclass
var.do_something(); // It is showing an error
obj.do_something(); // It is not giving any error
why ??