• 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

could anybody help me to find out the answers for these questions

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q)The static modifier is valid for
a) Class declarations
b) Class initialization blocks
c) Local variable declarations

Q)Consider the following code:

a)5
b) Compiler error, you cannot change a final variable
c) Compiler error, you cannot subclass from Cat
d) 6

[This message has been edited by Paul Wheaton (edited October 19, 1999).]
 
Trailboss
Posts: 23773
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(I gave your code sample a little formatting so it would be easier to understand)
Q1) Inner class declarations and class initialization blocks.
Q2) You could just copy this program into a couple of .java files, compile and run...
In my head, I think the answer will be 5.
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think i have two findings in your code.
First, the variable c is an instance variable in TestIt and can not be accessed inside a static method like main.
Second, even if we declare/define 'c ' inside main then we encounter the problem "Can't assign a value to a final variable: c"
So, to me, the question looks like a wrong one.
What do you think?
Rgds,
Saravanan
 
paul wheaton
Trailboss
Posts: 23773
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right on both counts!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic