Friday, March 11, 2016

Abstract and Interfaces.

There are ways to assist with inheritance and polymorphism which is done by abstract classes and interfaces these kinds of java files are used for different reasons. They both have abstract methods and those methods cannot be described like normal methods and have to be implemented in any child class of the abstract class and implemented classes.
public interface AnInteface{ // This is how to create an interface.
  public void aMathod(); // This is the way to instaciate an abstract method.
public abstract class AnAbstractClass{ // This is how to create an abstract class.
  public abstract void aMethod(); //This is another way to write an abstract method but abstract 
  // classes can also implement non-abstract methods.
 public String aString(){
  String a = "A string";
  return a;
There are two ways to implement these classes to another class:
public class NormalClass extends AnAbstractClass implements AnInterface{
 public void AMethod(){
 }// You have to incorporate the same abstract methods in a class that implements the interface or          // extends the abstract class 

1 comment: