Win a copy of Head First Android this week in the Android forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

2 enlightening exam qs ...

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 54.
True / False. Select if True

A.Instance variables are always initiated to defaults
B.Local variables are always initiated to defaults
C.Array Elements are always initiated to defaults
D.Object references that are not initialized
explicitly will have their value set to null always
//I LIKED A , C AND D, BUT D IS WRONG, WHY ? WHAT ARE THOSE CASES WHEN OBJ REFERENCES CANT BE SET TO NULL BY DEFAULT ?
Which are valid ?
A.float f = 1.2;
B.byte b = 255;
C.long l = ( long )f; /* f is a valid float variable */
D.char c = 100;
E. int i = (int) c1 + (int) c2;
/* where c1 & c2 valid char primitives */
F.boolean bo = null;
//I LIKED C AND D BUT ANSWER LIKES E AS WELL, IS THAT POSSIBLE, CAN CASTING BE DONE IN THIS FASHION , THANKS?!
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For q.54, I think this explains it. Object ref. are automatically initialised only if they are instance var. (not when they are local var).
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jini is correct about the first one.
For the second one, that is exactly how you cast chars to ints so this is perfectly valid. In fact, the cast is redundant because whenever you add two primatives they are going to be converted to at least an int automatically. If one of the two is larger than an int, then they are automatically converted to the larger value, but it will always be at least an int.
Bill
 
sarim raza
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks again Bill
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the options for Question 1 is elaborate ?.. in sense there are some options which does not tell whether it is local or instance declaration.
 
reply
    Bookmark Topic Watch Topic
  • New Topic