42
loading...
This website collects cookies to deliver better user experience
"When we talk about abstract classes we are defining characteristics of an object type; specifying **what an object is." ~Jorge, 2017.
abstract
. It can have both abstract and regular methods and can only be accessed in classes that inherit it.public abstract class Animal {
public abstract void makeSound();
public void sleep() {
System.out.println("Zzz");
}
}
public class Dog extends Animal {
public void makeSound() {
System.out.println("Uff uff!");
}
}
public class Main {
public static void main(String[] args) {
Dog snoopy = new Dog();
snoopy.makeSound();
snoopy.sleep();
}
}
"When we talk about an interface and define capabilities that we promise to provide, we are talking about establishing a contract about **what the object can do." ~Jorge, 2017.
interface
. In languages like C# and Java, there is a standard convention to prefix all interfaces with an I
, so a file handler interface will be IFileHandler
.public interface IWallet {
public void withdraw();
public void deposit();
double getBalance();
}
public class Wallet implements IWallet {
public void withdraw(){
//do something
}
public void deposit() {
//do something
}
double getBalance(){
//do something
}
}