1. Difference between Access Specifier and Access Modifier?
- Access Specifier tells visibility of the class and method within the other classes, package and etc. For example, public, private, protected and default.
- Access Modifier tells controlling of the class and method within the other classes, package and etc. For example, static, final, abstract, strictfp, syncronized, volatile, transient and native.
2. What are top level class access modifiers in JAVA?
The following five access modifier only applicable for the Top level class access modifier:
- public
- default
- final
- abstract
- strictfp
But inner classes allows extra modifiers such as private, protected and static.
3. What is the final modifier in JAVA?
Final keyword is used when declaring the entity that specifies the value of the entity can't be modifier in future. It is same as constant keyword in other languages.
- Final class can't be inherit anymore (Inheritance not allowed)
- Final method can't be redefined (Polymorphism not allowed)
- Final variable can't be reassigned (Re-initialization not allowed)
As mentioned above, it fails to satisfies the key benefits of OOPS. The main advantage of final keyword is providing security. Final keyword is not recommended to use if there is no requirement.
4. What will be the output?
public class T{
static int a = 5;
public static void main(String args[]){
new T().call();
}
void call(){
this.a++;
System.out.print(this.a);
}
}
A. Compile time error
B. Run time Exception
C. 5
D. 6
E. 0
Answer: Option D
Explanation:
Explanation:
5. What is strictfp?
If class or method is declared as strictfp, then all the concrete method inside a class or method has to follow IEEE standard results for floating arithmetic operations.
The result of floating point arithmetic operation is changes from one platform to other platform.
For Example, 10.0/3 results in windows platform as 3.33333333333335, in linux as 3.3333333 and in MAX 3.333333333334.
Eg:
6. Can we override static method?
7. How to prevent a method from being overridden?
8. What is transient variables?
9. Can we have static methods in interface?
10. Can a class in java be private?
Thank you for the questions
ReplyDelete