1

00:00:01,020  -->  00:00:07,800
So let's get started by learning about abstract classes and abstract methods and abstract class as the

2

00:00:07,800  -->  00:00:15,150
name suggests is a class that is too abstract which means that it is too generic to be instantiated

3

00:00:15,150  -->  00:00:15,670
.

4

00:00:16,080  -->  00:00:22,020
In other words it is not concrete enough to be instantiated on includes one or more methods for which

5

00:00:22,020  -->  00:00:27,450
it is not possible to provide any implementation even though it is not intangible.

6

00:00:27,480  -->  00:00:34,710
The class still plays an important role but defining a common protocol for all its subprocess so it

7

00:00:34,710  -->  00:00:42,240
defines a contract and hence can be used polymorphically on an abstract that is defined by simply inserting

8

00:00:42,240  -->  00:00:49,830
the key word abstract in the class declaration that the compiler ensures that the class cannot be instantiated

9

00:00:51,840  -->  00:00:57,930
like an abstract last and abstract method also involves inserting the key word abstract in the method

10

00:00:57,930  -->  00:01:04,930
declaration an abstract method will not have any body that is normally braces and it simply ends with

11

00:01:04,930  -->  00:01:10,130
that semicolon and its implementation will be provided by subprocess.

12

00:01:10,350  -->  00:01:14,010
That is a MUST be overridden.

13

00:01:14,040  -->  00:01:17,780
It also means that an abstract muttered cannot be declared as nothing.

14

00:01:17,910  -->  00:01:22,210
And that's because we know that static methods cannot be overridden.

15

00:01:23,340  -->  00:01:27,320
So an upstart class has no use unless it is extended.

16

00:01:27,540  -->  00:01:32,910
It may exist though defined only static members but that cannot be the only purpose of its existence

17

00:01:33,180  -->  00:01:35,970
and it would also be very confusing.

18

00:01:36,510  -->  00:01:42,650
So with an abstract class it is the instances of its subclasses which are doing the real work at runtime

19

00:01:42,660  -->  00:01:44,580
.

20

00:01:44,580  -->  00:01:46,980
Now let's look at some specifics.

21

00:01:47,250  -->  00:01:50,720
We cannot have an abstract method in a non abstract us.

22

00:01:51,090  -->  00:01:56,780
So if there is even one abstract method then the class must be abstract to us.

23

00:01:57,330  -->  00:02:03,450
In addition to abstract an abstract class may also contain one or more concrete methods that is methods

24

00:02:03,490  -->  00:02:06,080
with implementations.

25

00:02:06,330  -->  00:02:11,980
Not that an abstract class need not have any abstract methods but that is not typically done.

26

00:02:12,260  -->  00:02:17,910
It would be very confusing to have an abstract class without any abstract methods.

27

00:02:18,720  -->  00:02:22,960
So we know that implementation for abstract methods then be provided in subclasses.

28

00:02:23,370  -->  00:02:27,980
However a subclass itself can also be declared as abstract.

29

00:02:28,020  -->  00:02:34,230
That is it would be an abstract supperless and in this case that subclass doesn't have to override an

30

00:02:34,230  -->  00:02:36,250
inherited abstract method.

31

00:02:36,330  -->  00:02:39,640
It doesn't even have to really clear that inherited abstract matter.

32

00:02:39,900  -->  00:02:42,170
It means that some other subclass don't.

33

00:02:42,180  -->  00:02:47,970
The inheritance but would be expected to provide an implementation for that method.

34

00:02:47,970  -->  00:02:49,070
It can do it all right.

35

00:02:49,080  -->  00:02:50,370
Any inherited method.

36

00:02:50,460  -->  00:02:57,960
Whether or not the inherited method is abstract like any abstract class it can also define new abstract

37

00:02:58,170  -->  00:03:00,410
and concrete methods.

38

00:03:01,210  -->  00:03:09,100
No if a subclass is non-abstract which means that it is a concrete subclass then it must always right

39

00:03:09,110  -->  00:03:09,230
.

40

00:03:09,300  -->  00:03:12,500
All of the unimplemented abstract methods.

41

00:03:12,570  -->  00:03:17,970
All of the unimplemented abstract methods so some of the abstract methods might have been implemented

42

00:03:18,120  -->  00:03:19,740
in one or more super classes.

43

00:03:19,800  -->  00:03:26,220
And the inheritance tree only them it does that or not implement it must be implemented in this class

44

00:03:26,220  -->  00:03:27,020
.

45

00:03:27,210  -->  00:03:33,180
Otherwise we do get compilation errors and that's not really a short demo of abstract process or an

46

00:03:33,180  -->  00:03:38,010
abstract methods for this item or a new folder.

47

00:03:38,070  -->  00:03:41,100
Abstract has been added in the directory structure.

48

00:03:41,110  -->  00:03:46,290
Com semantics clear up three new classes have been added here.

49

00:03:46,290  -->  00:03:51,300
One is abstract superclass abstract subclass an concrete subclass.

50

00:03:51,390  -->  00:03:54,070
So let's just go ahead and look at these classes.

51

00:03:54,330  -->  00:03:56,160
So this is abstract superclass.

52

00:03:56,160  -->  00:04:03,750
This is the most class and it is an abstract class so it is declared with the keyword abstract here

53

00:04:04,050  -->  00:04:05,540
so it is an abstract class.

54

00:04:05,640  -->  00:04:10,570
I need to close to abstract methods so both the methods have the keyword abstract.

55

00:04:10,700  -->  00:04:17,460
So next let's look at the subclass of this which is an abstract subclass So it extends abstract superclass

56

00:04:18,090  -->  00:04:24,880
and it is also abstract and it is overwriting only one method which is a best one matter.

57

00:04:25,050  -->  00:04:30,450
So if you're going to abstract superclass you have test too so it's overloading only one method with

58

00:04:30,480  -->  00:04:37,260
just one and it is simply printing out this text just one and you can ignore this notation.

59

00:04:37,260  -->  00:04:43,080
It just implies that it is already one of the superclass methods but Farnam you can ignore it because

60

00:04:43,080  -->  00:04:49,790
it's covered in a separate chapter and it is also declaring its own abstract method and your method

61

00:04:49,800  -->  00:04:57,330
called Destiny Dometic pesto which is declared here is not is not overridden in this in this particular

62

00:04:57,330  -->  00:04:58,440
class.

63

00:04:58,440  -->  00:05:03,150
Now let's look at concrete of class which is a subclass of abstract subclass.

64

00:05:03,360  -->  00:05:09,390
OK so this is a concrete subclass so you don't see the keyword abstract here and there are two methods

65

00:05:09,390  -->  00:05:15,120
to be implemented from the inheritance hierarchy which is a test to test 3.

66

00:05:15,210  -->  00:05:21,840
So test to was declared as an abstract method and the topmost class on pastry was declared as an abstract

67

00:05:21,840  -->  00:05:23,880
method an abstract subclass.

68

00:05:23,880  -->  00:05:30,660
So this particular class has to provide implementation implementations for all the unimplemented abstract

69

00:05:30,660  -->  00:05:36,560
methods so it provides the implementations here as do industry and here is the main method.

70

00:05:36,600  -->  00:05:42,150
Here we are just instantiating this class concrete subclass and we are invoking all the three methods

71

00:05:42,150  -->  00:05:42,620
.

72

00:05:42,690  -->  00:05:46,870
So let's just go ahead and compile and run this.

73

00:05:46,890  -->  00:05:49,790
So I'm in the abstract folder.

74

00:05:50,400  -->  00:05:55,110
Just compile this and let me just run it.

75

00:05:55,410  -->  00:05:58,670
Did you go at Brent's test run test do and best three.

76

00:05:58,740  -->  00:06:02,170
Now let's just also uncommon this class.

77

00:06:02,460  -->  00:06:08,460
It's just creating an instance of an abstract class which should give a compiler error because abstract

78

00:06:08,460  -->  00:06:10,490
classes cannot be instantiated.

79

00:06:10,500  -->  00:06:17,880
So let me just try to recompile this and as you can see it's is abstract superclasses abstract cannot

80

00:06:17,940  -->  00:06:22,310
be instantiated So that's a compilation of that and that we are getting.

81

00:06:22,830  -->  00:06:26,690
So that's the demo for abstract classes on.
