and use interfaces in Java ✅ Explain what interfaces are useful for ✅ Define what an abstract class is ✅ Create and use abstract classes in Java ✅ Explain what abstract classes are useful for ✅ Explain the differences between abstract classes and interfaces
public static void main(String[] args) { Rectangle rectangle = new Rectangle(300, 200); Circle circle = new Circle(42); System.out.print("Rectangle: "); rectangle.printArea(); System.out.print("Circle: "); circle.printArea(); } } > Task :Main.main() Rectangle: The area is 60000.0 Circle: The area is 5541.769440932396
running ""... I'm Mario! I'm jumping ""... public class Main { public static void main(String[] args) { Character mario = new Character("Mario"); Game game = new Game(mario); game.makeCharacterRun(); game.makeCharacterJump(); } }
System.out.println("I'm a Mario! And I'm running normally !!..."); } @Override void run() { System.out.println("I'm a Mario! And I’m jumping normally !!..."); } } Let’s build Super Mario
Character mario = new Mario(); new Character("Mario") Game game = new Game(mario); game.makeCharacterRun(); game.makeCharacterJump(); } } Let’s build Super Mario > Task :Main.main() I'm a Mario! And I'm running normally ""... I'm a Mario! And I'm jumping normally ""...
System.out.println("I'm a Luiiiigi! And I'm jumping very high !!..."); } @Override void run() { System.out.println("I'm Luiiiigi! And I'm running normally!!..."); } } Let’s build Super Mario
void main(String[] args) { Character luigi = new Luigi(); new Character(“Luigi") Game game = new Game(luigi); game.makeCharacterRun(); game.makeCharacterJump(); } } > Task :Main.main() I'm Luiiiigi! And I'm running normally ""... I'm a Luiiiigi! And I'm jumping very high…
System.out.println("I'm Toad Toad! And I'm jumping normally!!..."); } @Override void run() { System.out.println("I'm Toad Toad! And I'm running very fast !!..."); } } Let’s build Super Mario
void main(String[] args) { Character toad = new Toad(); new Character(“Toad") Game game = new Game(toad); game.makeCharacterRun(); game.makeCharacterJump(); } } > Task :Main.main() I'm Toad Toad! And I’m running very fast ""... I'm Toad Toad! And I'm jumping normally ""...
classes are used to share common capabilities among subclasses. The difference here is that the specifics of the capabilities are known to subclasses only.
Can have methods and attributes ✅ Can have abstract methods (with no implementation) ✅ Can not be instantiated ✅ Can only be inherited ✅ Used to define common capabilities among subclasses but leaves the specifics of those capabilities to the subclasses
{ @Override public void throwFireBall() { System.out.println("I'm a Mario! And I'm throwing fire balls "); } @Override public void stomp() { System.out.print("I'm a Mario! And I'm destroying anything in my path!"); } }
{ @Override public void throwFireBall() { System.out.println("I'm a Mario! And I'm throwing fire balls "); } @Override public void stomp() { System.out.print("I'm a Mario! And I'm destroying anything in my path!"); } }
not have methods with implementations ✅ Classes conform to an interface by using the implements keyword ✅ A class can implement multiple interfaces ✅ Different and unrelated classes can implement the same interface ✅ Interfaces are used to capture behaviors shared by different objects
with implementations ✅ Can have public, private, protected attributes ✅ Adopted by using the extends keywordd ✅ A class can extend only one abstract class ✅ All the classes inheriting an abstract class are in the same “family” ✅ Used to define common capabilities among subclasses but leaves the specifics of those capabilities to the subclasses ✅ Declared using the interface keyword ✅ Can not have methods with implementations ✅ Can not have public, private, protected attributes ✅ Adopted by using the implements keywordd ✅ A class can implement as many interfaces as necessary ✅ Different and unrelated classes can implement the same interface ✅ Used to capture and abstract behaviors shared by different objects Abstract classes Interfaces