Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Interface vs Abstract Class

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 336
    Comment on it

    Interface
    Interface can extend many interface.
    Interface can extend from a interface only.
    Interface have only abstract method by default.
    Interface can have public method only it it.

    Abstract
    Abstract can attend only on class at a time.
    Abstract class can extend from both abstact class and class.
    A class can extend only one abstract class.
    Abstract class can have both protected, private method.
    Abstract Class

    /* the Figure class must be declared as abstract 
       because it contains an abstract method  */
    
    public abstract class Figure
    {
        /* because this is an abstract method the 
           body will be blank  */
        public abstract float getArea();    
    }
    
    public class Circle extends Figure
    {
        private float radius;
    
        public float getArea()
        {
            return (3.14 * (radius ^ 2));   
        }
    }
    
    public class Rectangle extends Figure
    {
        private float length, width;
    
        public float getArea(Figure other)
        {
            return length * width;
        }
    }
    

    Interface

    public interface Dog
    {
        public boolean Barks();
    
        public boolean isGoldenRetriever();
    }
    
    Now, if a class were to implement this interface, this is what it would look like:
    
    public class SomeClass implements Dog
    {
        public boolean Barks{
        // method definition here
    
        }
    
        public boolean isGoldenRetriever{
        // method definition here
        }
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: