• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Variable or An Object

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ranchers i have a doubt which you might find it silly,but still i have the doubt.

class B{}
class B1 extends B{}

B1 b1;
b1=(B)b1;

Here What I Want To know is what is b1 in the bold symbolises here,is it an object or a variable.

So If U are posting i just want you to post either
1)Object
or
2)Variable

Nothing else.Please Dont Post Any,any explainations.

Thanks,
With Regds,
Anand
 
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So If U are posting i just want you to post either
1)Object
or
2)Variable

Nothing else.Please Dont Post Any,any explainations.

The conditions you place on the answer are artificial; the answer depends on the context in which the term is used. So, since you demand that no explanation be given, there is no answer.

Let me know if you're willing to entertain an explanation, and I'll elaborate. Otherwise, I'll disregard.

Good luck.
[ September 21, 2005: Message edited by: Steve Morrow ]
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey hi steve ,
harish here
i need the explanation canu just explain with example
 
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think you just want to know what would you call b1 in the code


class B{}
class B1 extends B{}

B1 b1;
b1=(B)b1;



well i would say:
b1 is a Variable that may hold the reference of an Object of type B1

(If there is no compile time errror in the above mentioned code.)

As if:
String s="wow!!";

Here s is a variable holding the reference to the String object in the memory.

Hope it Clears something...
 
anand phulwani
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Explanation entertained!!please carry on with your explainations
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is an abstract from Sybex Complete Java 2 Certification
I Hope you would read it carefully to clear your doubts


Java programs do not deal directly with objects. They deal with references to objects. For
example, consider the following code:
Color purple = new Color(222, 0, 255);
The variable purple is not an object; it is a reference to an object. The object itself lives in memory
somewhere in the Java Virtual Machine (JVM). The variable purple contains something similar
to the address of the object. This address is known as a reference to the object. The difference
between a reference and an object is illustrated in Figure 4.8. References are stored in variables,
and variables have types that are specified by the programmer at compile time. Object reference
variable types can be classes (such as Graphics or FileWriter), interfaces (such as Runnable
or LayoutManager), or arrays (such as int[][] or Vector[]).



You could find you answer in this abstract.
[ September 21, 2005: Message edited by: Sandeep Chhabra ]
 
Steve Morrow
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd agree with and reiterate Sandeep's statement:

"b1" is a reference variable of the B1 type. It can hold references to objects of the B1 type, any reference to an object that is type-compatible with B1, or the null reference.

That's my "technical" explanation. In casual conversation, it's not wildly incorrect to say "b1 is an object", though the statement isn't technically precise.
[ September 21, 2005: Message edited by: Steve Morrow ]
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No objects are created so far. b1 is just a reference variable.
reply
    Bookmark Topic Watch Topic
  • New Topic