final in abstract

#2
Hi Friend,

No. we cant have final variables in abstract classes . Final declaration resists inheritance and also dont allow a final variable to be modified once it is declared . But as abstract classes might contain abstract methods, these abstract methods needs to be implemented in the class which extends from this class. And if at all the abstract method which is being overridden by the class which extends form this one uses this final variable ,there results in an error as final variables cant be modified once they are declared as they are constants .
 
#3
Can we have final variables in abstract classes?
NO
The abstract class is a class which contains abstract method and general methods. These methods have to be override for our purpose in the application. if we use a final keyword before any abstract class then we cant extend or inherit that class.
If use final before methods we cant override them.If use final before Variables we cant change the value ,i.e remains constant throughout the program
 
#5
Hi Friend,

No. we cant have final variables in abstract classes . Final declaration resists inheritance and also dont allow a final variable to be modified once it is declared . But as abstract classes might contain abstract methods, these abstract methods needs to be implemented in the class which extends from this class. And if at all the abstract method which is being overridden by the class which extends form this one uses this final variable ,there results in an error as final variables cant be modified once they are declared as they are constants .
please give some example
 
#6
ya sure, we can have final variable in the abstarct class there is no problem , but as we know we can use final variable in subclass which extends abstarct class but we cannt change its value.
I just explain you with example:

abstract class A
{
abstract void show();
final int wid=10;

}
public class Test2 extends A
{
public void show()
{
System.out.println("Hello show"+wid);
}

public static void main(String[] args)
{
Test2 t1=new Test2();
t1.show();
}
}


Output:
---------- Run Java Class ----------
Hello show10

Output completed (0 sec consumed) - Normal Termination
 
#8
A abstract class allows both final methods and final variables, but the abstract methods inside a abstract class cannot be final. In simple words, a method can either be final or abstract.
 
#9
Yes You can use final in abstract class but just remember that both the key word (abstract and final) can not use for a member
Ex-
abstract class Xyz
{
final int i = 10;//ok
abstract final void abc();// not allowed
}
 
#11
Class, which can't a chance to be instantiated should make its Questions. Instantiated Assuming that it overrides the sum theoretical routines Toward usage them. Superclass theoretical strategies may be itself abstract; Furthermore it can't be instantiated. ¥ java backs this is through the Pivotal word “final”.
 
Top