|
INTERVIEW QUESTIONS
J2EE
DETAILS
Question: Can we use variables in abstract or interface classes, If yes, then what are the limitations of their access modifiers. and if no, then why?
Answer: Interfaces ----------- An interface is a description of a set of methods that conforming implementing classes must have
All the variables defined in an interface must be static final, i.e. constants. Happily the values need not be known at compile time. You can do some computation at class load time to compute the values. The variables need not be just simple ints and Strings. They can be any type. Normally you leave off the static final as it is implicit
Abstract Classes ---------------- A class that is missing definitions for one or more methods. You can’t thus create an object of that class. You must first create a subclass and provide definitions for the abstract methods. Unlike interfaces, abstract classes may implement some of the methods. Though you can’t instantiate an abstract class, you can invoke its static methods.
You can declare variables with all access modifiers in the simailar lines of normal class.Only difference is we cannot create instance of abstract class where as we can for non-abstract classes
|
|
|
Category |
J2EE Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 6507 users |
Added on |
4/9/2015 |
Views |
67668 |
Rate it! |
|
|
Question:
Can we use variables in abstract or interface classes, If yes, then what are the limitations of their access modifiers. and if no, then why?
Answer:
Interfaces ----------- An interface is a description of a set of methods that conforming implementing classes must have
All the variables defined in an interface must be static final, i.e. constants. Happily the values need not be known at compile time. You can do some computation at class load time to compute the values. The variables need not be just simple ints and Strings. They can be any type. Normally you leave off the static final as it is implicit
Abstract Classes ---------------- A class that is missing definitions for one or more methods. You can’t thus create an object of that class. You must first create a subclass and provide definitions for the abstract methods. Unlike interfaces, abstract classes may implement some of the methods. Though you can’t instantiate an abstract class, you can invoke its static methods.
You can declare variables with all access modifiers in the simailar lines of normal class.Only difference is we cannot create instance of abstract class where as we can for non-abstract classes Source: CoolInterview.com
Answered by: Srinivas Belidhe | Date: 4/18/2010
| Contact Srinivas Belidhe
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All J2EE Interview Questions & Answers - Exam Mode /
Learning Mode
|