Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference to extend abstract class and non abstract class?

What is difference between abstract class and non abstract class when extending derived classes? Both class I didn't use the method overriding and abstract methods (i.e. abstract class). Just I inherited the properties. What and why did prefer the class?

Ex:

Code 1:

abstract class a {  
    protected int empnno; 
    protected String empname; 
} 

class b extends a { 
    ...
}

Code 2:

class a {  
    protected int empnno; 
    protected String empname; 
}

class b extends a { 
    ...
}
like image 687
techsuri Avatar asked Nov 09 '11 11:11

techsuri


1 Answers

what is difference to extend abstract class and non abstract class?

Abstract classes may have abstract methods. Abstract methods are methods without implementations and these must be implemented by your subclass (unless you make your subclass abstract too).

Since your a class have no abstract methods, there is no difference what so ever from a subclass-perspective. (The only difference is that if a is abstract it may no longer be instantiated as is. It may only be instantiated in terms of subclasses.)

like image 171
aioobe Avatar answered Oct 16 '22 06:10

aioobe