What is the difference between Abstract Class and Interface

Answer Posted / vikrant

Nothing stops you using interfaces and abstract classes
interchangeably. The difference is in the ideology where to
use it.

An abstract class is to be used when one needs to create a
hierarchy. e.g. Poodle, Pointer and Chihuahua are all breeds
breeds of dogs, they have some common characteristics as
dogs and some special characteristics of its breed. so all
breeds (Poodle, Pointer and Chihuahua classes) will inherit
from the Dog class.

Interface on the other hand is just a contract. The
implementing classes need not be related. Say a 3-D figure.
Sphere, Cone, Cylinder are all 3-D shapes they have nothing
in common apart from being 3-D figures. Each will have their
own equation for calculating area, perimeter, volume. All
need to specify in Shapes interface is that the implementing
class must be able to calculate area, perimeter, volume.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is use of arraylist in java?

579


What is the difference between length and size in java?

492


What is class and object in java?

545


What is the difference between yielding and sleeping?

551


You can create a string object as string str = “abc”; why cant a button object be created as button bt = “abc”;? Explain

526






What is an object in java and how is it created?

581


For ease of programming you can consider the maze as a 2D array with colors represented by below integer and characters (in capital letters). • B - Black • W -White • G- Green • R- Red R B W B W W W W W W B W B B W W W W W W W B W B W W W B W W W W B B W W W B W W W B W W B B B B W B W B W W B W W W B W W W B B B W W B W W W B W W B W B W W W B W B W W W W B B W W W W B W W W W W G Shortest Route Problem: • Solution that finds the shortest Route between Red and Green  White will have 1 Weight.  Red and Green carry no weights.  Shortest path is the path with less weight when you add up the weights in the path.

1579


Is arraylist sorted in java?

525


What is a numeric digit?

582


Objects or references which of them gets garbage collected?

530


What is difference between static and abstract class?

514


What do you mean by of string::valueof expression in java 8?

539


What is the use of optional ?

562


What is the protected method modifier?

560


In a container there are 5 components. I want to display all the component names, how will you do that?

1557