+ 1

Variable and Object

What is the difference between variable and object in Java.

20th Jul 2019, 8:11 PM
Ujjawal Dubey
Ujjawal Dubey - avatar
13 odpowiedzi
+ 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.
20th Jul 2019, 10:38 PM
zemiak
+ 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.
20th Jul 2019, 8:42 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 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() ;
20th Jul 2019, 9:08 PM
Ujjawal Dubey
Ujjawal Dubey - avatar
+ 1
~ swim ~ Ok. please tell me, what does var do?
20th Jul 2019, 9:18 PM
Ujjawal Dubey
Ujjawal Dubey - avatar
+ 1
~ swim ~ thanks 😊
20th Jul 2019, 9:27 PM
Ujjawal Dubey
Ujjawal Dubey - avatar
+ 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.
21st Jul 2019, 12:02 AM
Ayush Pandey
Ayush Pandey - avatar
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 ??
20th Jul 2019, 8:38 PM
Ujjawal Dubey
Ujjawal Dubey - avatar