+ 1
Guys who can explain more about abstraction?
2 Réponses
+ 1
An abstract class in simple words is a class that has one abstract method or more without implementation. The abstract method should be implemented by the subclasses
ex:
abstract class Food{
public static final int FRUIT=1;
public static final int VEG=2;
public abstract int getType();
public void eat(){
System.out.println("eating...yummy");
}
}
class Fruit extends Food {
public int getType(){
return Food.FRUIT;
}
}
public class Program
{
public static void main(String[] args) {
Fruit f = new Fruit();
f.eat();
if(f.getType() == Food.VEG){
System.out.print("Vegetable");
}else{
System.out.print("Fruit");
}
}
}
0
abstract class in simple word contain method without body define in super class and method declared in subclass