• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Some basic questions - part 2

 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Q3)Which of the following are valid member variable declarations?
a] abstract int i;
b] final int i;
c] final volatile int i;
d] public transient final i
e] protected static final int i
Q4)Which of the following are true regarding interfaces?
a] All methods in an interface are public,abstract and static
b] All interface methods should have public accessibility when implemented in class
c] All variables in an interface are public,static and final
d] interfaces can have constructors
e] It is valid to declare the methods explicitly in an interface as static.

 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit,
Please post one question per thread. Trying to discuss too many things under one topic will convolute the discussion and cannot be of much help to anyone!
Also, when you post questions, think aloud and tell us what you think. Try to answer the question and analize why those answers are right or wrong. This way others can help you re-orient your way of thinking.
These comments apply to all other messages posted by you. You may edit your old messages to separate the questions, or simply post new messages.
Thanks!
Ajith
 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here are my answers to the questions:

q3) I think that all the answers are false because a variable cannot be abstract and final variables have to be initialized when they are declared.
Q4) a) false : methods in an interface cannot be static.
b) true : while overriding methods the accessibility cannot be made more restrictive.
c) true : variables in an interface are implicitly public, static and final.
d) false : interfaces cannot be instantiated. So constructors don't come into picture.
e) false : same reason as in a).
 
natarajan meghanathan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we can still allow final variables to be declared as posted above, since if they are not initialized, they have to be initialized in the constructors or initializer expressions. I don't think such vague Q.s are asked!!!
 
natarajan meghanathan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
volatile variables cannot be final!!!
So only option b is correct!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic