• 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

Compile time question for you

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
/* 1 */ class T2 {
/* 2 */ int j = i;
/* 3 */ static final int i = 10;
/* 4 */ static void main (String [] args) {
/* 5 */
/* 6 */ b = i + 1 > 4;
/* 7 */ boolean b = (boolean) i;
/* 8 */ i = (int) b;
/* 9 */ System.out.println(b);
/* 10 */
/* 11 */ }
}
/*
Which lines generate compile time errors (circle all that apply)
1
2
3
4
5
6
7
8
9
*/

I made this question up, so you will have trouble finding it on any other sites. However, I also made up the syntax, with the line numbers over on the left in comments. I think this represents a substantial improvement over many other code examples- because you can cut and paste it and compile it immediately! No mucking around with editing. I hope others adopt this standard.


However, I am not sure where to post the answers- I hope you try compiling it you may be surprised at the results in multiple places.
[ September 03, 2004: Message edited by: Tom Tolman ]
[ September 03, 2004: Message edited by: Tom Tolman ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tom, please quote the source of your question when you post.
Thanks,
-Barry
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At first glance , these 3: (6 , 7 + 8)

b = i + 1 > 4; // compiler will complain that b is undefined
boolean b = (boolean) i; // can't cast from int to boolean
i = (int) b; // can't assign i as it is final

These lines I think are fine :
int j = i; //j is being assigned the value of a static variable ??? so compiler won't complain
static final int i = 10;
 
To get a wish, you need a genie. To get a genie, you need a lamp. To get a lamp, you need a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic