what is the difference b/w static and final methods?
Answer / guest
There is lot of difference b/w static and final Method....
Static Method.....
1). Static Method is part of class object. all static method
is loading after class is loading into the Memory(i.e heap).
2). All static Method can be access by Either class Name or
instance of the class.
3). While static method accessing by instance of the class
compiler is internally it converting into it's class reference.
4). Static methods can't be override.
5). By static Method we can't achieve Dynamic Method
dispating functionally.
6). static method is part of class object only.
7). Static method can't be call the non-static method
directly(i.e without creating instance of the class)
8). But Non static method can call the static methods.bcz of
static method are universal method these can be access by
any where either by class Name or by intance of the class.
Final Methods....
1). Final method are followed by final keyword.
2). Final method can't be inherited in subclass.
3). Final method can't be override in subclass also.
4). Final methods are faster than non-final methods because
they are not required to be resolved during run-time and
they are bonded on compile time.
For example
class PersonalLoan{
public final String getName(){
return "personal loan";
}
}
class CheapPersonalLoan extends PersonalLoan{
@Override
public final String getName(){
return "cheap personal loan"; //compilation error:
overridden method is final
}
}
| Is This Answer Correct ? | 9 Yes | 0 No |
11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. static class B extends A { 15. void process() { System.out.println(”B”); } 16. } 17. public static void main(String[] args) { 18. new B().process(); 19. } What is the result? 1 B 2 The code runs with no output. 3 Compilation fails because of an error in line 12. 4 Compilation fails because of an error in line 15.
What is cloneable interface?
How does arraylist work in java?
Hi Friends, can u give code to convert ArrayList to HashMap and HashMap to ArrayList.
How can you read an integer value from the keyword when the application is runtime in java? example?
Explain differences between checked and unchecked exceptions in java?
How do you access command-line arguments within the code?
0 Answers Flextronics, Hexaware,
if num=687; U have to get num=6+8+7;
What are voids?
Is null keyword in java?
When throws keyword is used?
What do you mean by ordered and sorted in collections in java?