• 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

About references .....

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
i came a cross a mock exam with question like
this :
String a, b;
a = new String("xpto" );
Integer c,d;
c = new Integer ( 10 );
How many object's, references ?
the objects part it's easy, we've got 2.
but regarding references, i hava some dough'ts.
only a and c reference Objects. b,d don't.
my question would be, there are two references, am i right ?

best regards
Lu�s Meira
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, there are 4 references: a, b, c, & d. Two of them reference null, but they are still reference variables.
Corey
 
luis meira
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Corey McGlone:
No, there are 4 references: a, b, c, & d. Two of them reference null, but they are still reference variables.
Corey


many thanks
best regards
Luis Meira
 
luis meira
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Corey McGlone:
No, there are 4 references: a, b, c, & d. Two of them reference null, but they are still reference variables.
Corey


many thanks
best regards
Luis Meira
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by luis meira:
Hello everyone,
i came a cross a mock exam with question like
this :
String a, b;
a = new String("xpto" );
Integer c,d;
c = new Integer ( 10 );
How many object's, references ?
the objects part it's easy, we've got 2.
but regarding references, i hava some dough'ts.
only a and c reference Objects. b,d don't.
my question would be, there are two references, am i right ?



Why 2 objects, not 3?
a = new String("xpto" );
Are 2 objects are created?
c = new Integer ( 10 );
1 object is created, right?
Let me know the correct understanding.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is what u said about the java literal pool?
as i think,when first created,literals will be pooled,but i dont understand how to implement the pool,and what is the scope of the pool?
if it is process-ranged,it is easy to explain:
when create a litaral,JVM will remember its address or refernce but doesnt create a new object for the pooled object for the new operation,but just remember the address of the object
 
luco zhao
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Steven Sun:
is what u said about the java literal pool?
as i think,when first created,literals will be pooled,but i dont understand how to implement the pool,and what is the scope of the pool?
if it is process-ranged,it is easy to explain:
when create a litaral,JVM will remember its address or refernce but doesnt create a new object for the pooled object for the new operation,but just remember the address of the object



Thanks anyway, now I understand it quite well by reading some great posts here.
BTW, r u from NJ/SH?Thx
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have any questions about the String literal pool, just take a look through this thread. It covers the topic very well.
Corey
reply
    Bookmark Topic Watch Topic
  • New Topic