Loading…
Transcript

USAGE

DEFINITION

INTERFACE:

  • methods without their bodies
  • constant fields - implicitly public, final, and static
  • classes implementing an interface should implement all their methods!
  • a class can implement multiple interfaces

JAVA

Interface:

  • can be extended by another interface
  • can be implemented by a class
  • can be passed as parameter to a method -> if an interface type is required as an argument, you can pass any object whose class implements this interface

ABSTRACT class:

  • can be extended by another class

ABSTRACT class can have:

  • data member,
  • abstract method
  • non-abstract method
  • constructor
  • cannot be instantiated
  • a class extending an abstract class shouldn't extend all its methods
  • a class can only extend only one single [abstract] class

1 - N: 1 interface can EXTEND multiple interfaces

INTERFACE

1 - N: 1 class can IMPLEMENT multiple interfaces

Abstract CLASS

MAIN

1 - 1: 1 class can EXTEND one single other class

1 - N: 1 class can BE EXTENDED by multiple classes

Static CLASS

CLASS

ABSTRACTION

STATIC:

  • @class level, not associated with an instance of a class
  • static values:
  • passed by reference

STATIC class:

  • can be used by other class or in main
  • variables and methods are accessed only at CLASS level:
  • eg: Integer.parseInt()

CANNOT

1 - N: 1 class can be INSTANTIATED by multiple objects

OBJECT

OBJECTS:

  • CREATE - to instantiate objects through constructors:
  • new - key word:
  • allocates the memory described by the class, and runs the constructor
  • returns a reference to the allocated memory
  • apply methods defined in the class definition on the objects:
  • RETRIEVE info: sufragerie.scaun.getCuloare()
  • UPDATE info:

CLASSES - contains:

  • variables
  • primitive types
  • ENUM / finals
  • reference types (classes)
  • Date / String / Integer or
  • custom classes defined by us
  • collections
  • methods - contains all logic & operations
  • takes parameters:
  • none ()
  • a primitive type, an object, an interface
  • returns a result:
  • void
  • a primitive type, an object
  • eg:
  • constructors - to instantiate an object
  • getter, setter
  • other operations