Difference between revisions of "Java/C3/Abstract-Classes/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with " {| Border=1 | <center>'''Time'''</center> | <center>'''Narration'''</center> |- | 00:01 | Welcome to the Spoken Tutorial on''' Abstract Classes.''' |- | 00:05 | In thi...")
 
Line 1: Line 1:
 
+
{| border=1
{| Border=1
+
| <center>'''Time'''</center>
| <center>'''Time'''</center>
+
| <center>'''Narration'''</center>
| <center>'''Narration'''</center>
+
  
 
|-
 
|-
| 00:01
+
| 00:00
| Welcome to the Spoken Tutorial on''' Abstract Classes.'''
+
| Welcome to the Spoken Tutorial on''' Abstract Classes.'''
  
 
|-
 
|-
| 00:05
+
|00:05
| In this tutorial we will learn about:  '''Abstract Methods '''and''' Concrete Methods'''
+
| In this tutorial we will learn about:  '''Abstract Methods '''and''' Concrete Methods'''
  
 
|-
 
|-
 
| 00:12
 
| 00:12
| '''Abstract Classes '''and''' Concrete Classes '''and
+
| '''Abstract Classes '''and''' Concrete Classes '''and
  
 
|-
 
|-
| 00:15
+
| 00:16
 
| How to use '''Abstract Classes'''
 
| How to use '''Abstract Classes'''
  
 
|-
 
|-
| 00:18
+
| 00:18
| For this tutorial, I am using
+
| For this tutorial, I am using
 +
 
 
* '''Ubuntu 12.04'''
 
* '''Ubuntu 12.04'''
 
* '''JDK 1.7 '''and
 
* '''JDK 1.7 '''and
Line 28: Line 28:
  
 
|-
 
|-
| 00:28
+
|00:28
| To follow this tutorial, you should have knowledge of basics of''' Java''' and''' Eclipse IDE.'''
+
| To follow this tutorial, you should have knowledge of basics of''' Java''' and''' Eclipse IDE.'''
  
 
|-
 
|-
 
| 00:36
 
| 00:36
| You should also have the knowledge of''' subclassing '''in''' Java.''' If not, for relevant''' Java '''tutorials, please visit the link shown.
+
|You should also have the knowledge of''' subclassing '''in''' Java.'''
  
 
|-
 
|-
| 00:46
+
| 00:40
| First we will see about '''Abstract Method'''.
+
|If not, for relevant''' Java '''tutorials, please visit the link shown.
  
 
|-
 
|-
| 00:50
+
|00:46
| An '''Abstract method''' is a''' method''' that is declared without implementation.
+
|First we will see about '''Abstract Method'''.
  
 
|-
 
|-
| 00:55
+
|00:50
| It is declared using''' abstract '''keyword. There should not be opening and closing parenthesis for this '''method'''.
+
| An '''Abstract method''' is a''' method''' that is declared without '''implementation'''.
  
 
|-
 
|-
| 01:04
+
| 00:55
| The''' method showDetails()''' illustrated here, is an example of''' abstract method'''.
+
|It is declared using''' abstract keyword'''.
  
|-
 
| 01:10
 
| Note that this '''method''' is declared using the''' abstract '''keyword, with no current implementation.
 
  
 
|-
 
|-
| 01:18
+
| 00:59
| Next we will see about '''concrete method'''.
+
|There should not be opening and closing parenthesis for this '''method'''.
  
 
|-
 
|-
| 01:21
+
|01:04
| A '''Concrete method''' is completely implemented within the curly brackets.
+
|Let us understand the usage of '''Abstract class '''with a sample program.
  
 
|-
 
|-
| 01:27
+
|01:09
| This method''' showBasicDetails()''' illustrated here is an example of '''concrete method'''.
+
|Now we will switch to''' Eclipse''' and create a new '''project''' called '''AbstractDemo'''.
  
 
|-
 
|-
| 01:35
+
| 01:16
| Observe that this '''method''' is implemented completely.
+
|Inside this '''project''' we will create the necessary '''classes''' to demonstrate the usage of''' Abstract class.'''
  
 
|-
 
|-
| 01:39
+
|01:24
| Now we will learn about '''abstract class''' with an example.
+
|Now, right click on '''src''' folder and click '''New-'''> '''Class'''.
  
 
|-
 
|-
| 01:44
+
|01:30
| An''' abstract class''' usually contains at least one''' abstract method'''.
+
|Type the name of the '''class''' as '''Person''' and press '''Enter'''.
  
 
|-
 
|-
| 01:49
+
|01:35
|   '''Abstract methods '''can be added only to '''abstract classes.'''
+
|Now we will add the fields to represent the name and the age of the''' Person'''. Type''' String name semicolon.'''  
  
 
|-
 
|-
| 01:54
+
|01:44
| The '''class Person''' illustrated here is an''' abstract class.'''
+
|Also type''' int age semicolon.'''
  
 
|-
 
|-
| 01:59
+
|01:48
| It contains an''' abstract method''' called''' showDetails()'''.
+
|Now click on''' Source ->''' and select''' Generate constructor using fields. '''
  
 
|-
 
|-
| 02:04
+
|01:55
| It can also contain '''variables''' and other '''concrete methods.'''
+
|Delete the '''super keyword''' from the generated code.
  
 
|-
 
|-
| 02:09
+
|01:59
| The figure here represents an '''inheritance relation'''. Here, the''' Person class''' is an''' abstract class.'''
+
|The '''constructor''' can initialise the values of '''name''' and '''age '''fields.
  
 
|-
 
|-
| 02:18
+
|02:05
| The''' Employee class''' and the '''Student class''' are '''subclasses''' of the''' Person class'''.
+
|Next we will see about '''concrete method'''.
  
|-
 
| 02:24
 
| These '''subclasses''' can provide their own different implementations.
 
  
 
|-
 
|-
| 02:29
+
|02:08
| These are done by''' showDetails( ) method''' present in the''' Person class.'''
+
|A '''Concrete method''' is completely implemented within the curly brackets.
  
 
|-
 
|-
| 02:35
+
|02:14
| For example: '''ShowDetails() Method''' in the''' Employee class''' prints the '''Employee ID''' and the''' Salary''', where as  '''ShowDetails() Method''' in the''' Student class''' prints the '''Student Reg No''' and the '''Grade.'''
+
|We will add a''' concrete method''' to this '''class''' to print the name and age.  
  
 
|-
 
|-
| 02:49
+
|02:21
| A '''class''' is said to be a''' concrete class,''' if all the '''methods''' in that '''class''' are''' concrete methods'''.  
+
|Type the following code as displayed on the screen.
  
 
|-
 
|-
| 02:57
+
|02:25
| The '''class Employee''' illustrated here, is a''' concrete class'''.  All the '''methods''' inside this '''class''' including''' showDetails()''' are '''concrete'''.
+
|This '''method showBasicDetails()''' illustrated here, is an example of '''concrete method'''.
  
 
|-
 
|-
| 03:07
+
|02:32
| Let us understand the usage of '''Abstract class '''with a sample program.
+
|Observe that this '''method''' is implemented completely.
  
 
|-
 
|-
| 03:12
+
|02:36
| Now we will switch to''' Eclipse''' and create a new '''project''' called '''AbstractDemo'''.
+
|Now we will add an '''abstract method''' to this '''class'''.
  
 
|-
 
|-
| 03:19
+
|02:41
| Inside this '''project''', we will create the necessary '''classes''' to demonstrate the usage of''' Abstract class.'''
+
|So type '''public void showDetails( )''' semicolon.
  
 
|-
 
|-
| 03:27
+
|02:46
| Now, right click on '''src''' folder and click '''new-'''> '''class'''.
+
|An error comes up, since we have not yet added the''' abstract  keyword. '''
  
 
|-
 
|-
| 03:33
+
|02:51
| Type the name of the '''class''' as '''Person''' and press '''Enter'''.
+
|So now add the '''keyword abstract.'''
  
 
|-
 
|-
| 03:38
+
|02:55
| Now we will add the fields to represent the name and age of the''' Person'''.
+
|Now we can see another error comes up.
  
 
|-
 
|-
| 03:44
+
|02:58
| Type''' String name semicolon.''' Also type''' int age semicolon.'''
+
|This is because, '''abstract methods''' can be added only to '''abstract classes'''.
  
 
|-
 
|-
| 03:51
+
|03:03
| Now click on''' source ->''' and select''' generate constructor using fields. '''
+
|So now add the''' keyword abstract''' to the''' Person class '''to make it an''' abstract class.'''
  
 
|-
 
|-
| 03:58
+
|03:10
| Delete the '''super '''keyword from the generated code.
+
|The '''class Person''' illustrated here is an''' abstract class.'''
 +
 
  
 
|-
 
|-
| 04:02
+
|03:15
| The '''constructor''' can initialise the values of '''name''' and '''age '''fields.
+
|It contains an''' abstract method''' called''' showDetails()'''.
  
 
|-
 
|-
| 04:08
+
|03:20
| We will add a''' concrete method''' to this '''class''' to print the name and age.  
+
| The figure here represents an '''inheritance relation'''.
  
 
|-
 
|-
| 04:14
+
|03:24
| So type '''public void showBasicDetails( )''' within '''brackets''' type, '''System.out.println''' within round brackets and within quotes type''' Name colon''' plus''' name semicolon'''
+
|Here, the''' Person class''' is an''' abstract class.'''
  
 
|-
 
|-
| 04:33
+
|03:29
| Also type '''System.out.println''' within round brackets and within quotes''' Age colon''' plus''' age semicolon'''
+
|The''' Employee class''' and the '''Student class''' are '''subclasses''' of the''' Person class'''.
  
 
|-
 
|-
| 04:46
+
|03:35
| Now we will add an '''abstract method''' to this '''class'''. So type '''public void showDetails( ) semicolon'''
+
|These '''subclasses''' can provide their own different implementations.
  
 
|-
 
|-
| 04:56
+
|03:40
| An error comes up, since we have not yet added the''' abstract '''keyword.  
+
| These are done by''' showDetails( ) method''' present in the''' Person class.'''
  
 
|-
 
|-
| 05:01
+
|03:45
| So now, add the keyword '''abstract.'''
+
|For example: '''ShowDetails() Method''' in the''' Employee class''' prints the '''Employee ID''' and the''' Salary''', where as '''ShowDetails() Method''' in the''' Student class''' prints the '''Student Register Number''' and '''Grade.'''
  
 
|-
 
|-
| 05:04
+
| 04:01
| Now we can see, another error comes up. This is because, '''abstract methods''' can be added only to '''abstract classes'''.
+
| Then right-click on the '''default package''' and create another''' class''' called''' Employee.'''
  
 
|-
 
|-
| 05:13
+
|04:07
| So now, add the keyword''' abstract''' to the''' Person class '''to make it an''' abstract class.'''
+
|Now to make this a '''subclass''' of '''Person class, '''type''' extends Person'''.
  
 
|-
 
|-
| 05:20
+
| 04:14
| Then right click on the '''default package''' and create another''' class''' called''' Employee.'''
+
| Now we can see an error comes up in the '''Eclipse IDE.'''
  
 
|-
 
|-
| 05:26
+
|04:19
| Now to make this a '''subclass''' of '''Person class, '''type''' extends Person'''.
+
|It indicates that, we should provide an '''implementation''' to the '''abstract method showDetails( )'''.
  
 
|-
 
|-
| 05:34
+
|04:26
| Now we can see an error comes up in the '''Eclipse IDE.'''
+
|We will do it a little later.
  
 
|-
 
|-
| 05:38
+
| 04:28
| It indicates that, we should provide an implementation to the '''abstract method showDetails( )'''.
+
| Now create two fields to represent the '''employee id''' and '''employee salary'''.  
We will do it a little later.
+
  
 
|-
 
|-
| 05:48
+
|04:34
| Now create two fields to represent the '''employee id''' and '''employee salary'''.
+
|So type''' String empid semicolon''' and''' int salary semicolon'''
  
 
|-
 
|-
| 05:54
+
|04:42
| So type ''' String empid semicolon''' and''' int salary semicolon'''
+
|Now click on '''Source'''-> and then select''' Generate constructor using fields.'''  
  
 
|-
 
|-
| 06:01
+
|04:49
| Now click on '''source'''-> and then select''' generate constructor using fields.'''  
+
|This '''constructor''' can initialise the values of '''name, age, empid '''and''' salary'''.
  
 
|-
 
|-
| 06:08
+
| 04:56
| This '''constructor''' can initialise the values of '''name, age, empid '''and''' salary'''.
+
| Let us now define the''' showDetails method'''. So type''' public void showDetails( ).'''
  
 
|-
 
|-
| 06:15
+
|05:04
| Let us now define the''' showDetails method'''. So type''' public void showDetails( )'''
+
|Inside this '''method''', we need to print the employee details.
  
 
|-
 
|-
| 06:23
+
|05:09
| Inside this '''method''', we need to print the employee details.  
+
|Type the following code as displayed on the screen.  
  
 
|-
 
|-
| 06:27
+
|05:13
| So type '''System.out.println''' within quotes''' Emp id colon''' plus''' empid semicolon'''
+
|Note that the error disappears, once the '''showDetails() method''' is implemented.
  
 
|-
 
|-
| 06:38
+
|05:19
| '''System.out.println''' within quotes''' Salary colon''' plus''' salary semicolon'''
+
|Next we will see a '''Student class''' of the '''project'''.
  
 
|-
 
|-
| 06:47
+
|05:23
| Note that the error disappears, once the '''showDetails() method''' is implemented.
+
|I have already created a '''subclass''' called''' Student'''.
  
 
|-
 
|-
| 06:54
+
|05:28
| Next we will see a '''Student class''' of the '''project'''.
+
| There are two fields in the '''Student class – register number''' and''' grade''' which represent student egister number and grade.
  
 
|-
 
|-
| 06:57
+
| 05:37
| I have already created a '''subclass''' called''' Student'''.
+
| A '''constructor''' is also created inside this '''class'''.  
  
 
|-
 
|-
| 07:02
+
|05:42
| There are two fields in the '''Student class, regno (register number) ''' and''' grade''' which represent '''student reg. no (register number)''' and '''grade'''.
+
|This '''constructor''' can be used to initialize the values for''' name, age, register number '''and''' grade.'''
  
 
|-
 
|-
| 07:11
+
| 05:50
| A '''constructor''' is also created inside this '''class'''. This '''constructor''' can be used to initialize the values for''' name, age, register number '''and''' grade.'''
+
| The''' showDetails method''' is also implemented in this '''class'''.  
  
 
|-
 
|-
| 07:24
+
|05:56
| The''' showDetails method''' is also implemented in this '''class'''.  It prints the values of''' Student Reg. Number''' and''' grade'''
+
|It prints the values of''' Student Register Number''' and''' grade'''
  
 
|-
 
|-
| 07:34
+
| 06:00
 
| Now note that the''' Employee class''' has its own implementation of''' showDetails().'''
 
| Now note that the''' Employee class''' has its own implementation of''' showDetails().'''
  
 
|-
 
|-
| 07:42
+
|06:08
| And the''' Student class''' has its own implementation of''' showDetails().'''
+
|And the''' Student class''' has its own implementation of''' showDetails().'''
  
 
|-
 
|-
| 07:48
+
| 06:14
| Now right click on the '''default package.'''  Click on '''new'''-> '''class''' and then type name as''' Demo.'''
+
| Now right-click on the '''default package.'''  
  
 
|-
 
|-
| 07:57
+
|06:17
| Inside this '''class''', we will have the '''main method''', So type '''main''' and then press '''Ctrl space''' to generate the''' main method.'''
+
|Click on '''New'''-> '''Class''' and then type name as''' Demo. '''
  
 
|-
 
|-
| 08:08
+
|06:23
| Now let us try to instantiate the''' Person class''' by typing '''Person p equals new Person.'''
+
|Inside this '''class''' we will have the '''main method''',
  
 
|-
 
|-
| 08:16
+
|06:27
| Within brackets and double quotes, type '''John''' and put a '''semicolon'''.
+
|So type '''main''' and then press ctrl+space to generate the''' main method.'''
  
 
|-
 
|-
| 08:23
+
| 06:33
| Now we can see an error. This is because the''' Person class''' is '''abstract''' and it cannot be instantiated. Let's remove this line.
+
| Now let us try to instantiate the''' Person class''' by typing '''Person p equals new Person.'''
  
 
|-
 
|-
| 08:34
+
|06:42
| Type the following code as displayed on the screen.
+
|Within brackets and double quotes type '''John''' and put a semicolon.
  
 
|-
 
|-
| 08:38
+
|06:48
| Now let us instantiate the''' Person class''' using the''' Employee class''' as '''Person p1 equals new Employee.'''
+
|Now we can see an error. This is because the''' Person class''' is '''abstract''' and it cannot be instantiated.
  
 
|-
 
|-
| 08:48
+
|06:58
| In the first line, we are passing the values of different '''arguments'''.
+
|Let's remove this line.
  
*'''John''' is passed as '''Employee name''',
+
|-
 +
| 07:00
 +
| Type the following code as displayed on the screen.
  
 
|-
 
|-
| 08:57
+
|07:04
| '''40''' as the value of '''age. E267''' as the value of '''Employee ID''' and
+
|Now let us instantiate the''' Person class''' using the''' Employee class''' as '''Person p1 equals new Employee.'''
  
 
|-
 
|-
| 09:04
+
|07:14
| '''10000''' as the value of '''Employee salary.'''
+
|In the first line, we are passing the values of different arguments.
  
 
|-
 
|-
| 09:07
+
|07:19
| Now we can invoke the '''concrete method''' in the '''Person class''' as '''p1.showBasicDetails()'''
+
|'''John''' is passed as '''Employee name'''.  
  
 
|-
 
|-
| 09:16
+
|07:22
| We can also call the''' showDetails() method''' using the '''object p1''' as '''p1.showDetails()'''
+
|'''40''' as the value of '''age.'''
  
 
|-
 
|-
| 09:24
+
|07:25
| Similarly, instantiate the''' Person class''' using the''' Student class'''. This is represented as '''Person p2 equals new Student.'''
+
|'''E267''' as the value of '''Employee ID''' and '''10000''' as the value of '''Employee salary.'''
  
 
|-
 
|-
| 09:35
+
|07:33
| Now we are passing the values of different '''arguments'''.
+
|Now we can invoke the '''concrete method''' in the '''Person class''' as '''p1.showBasicDetails()'''
  
'''Hari''' is passed as the value of''' student name''',
+
|-
 +
|07:41
 +
|We can also call the''' showDetails() method''' using the '''object p1''' as '''p1.showDetails()'''
  
 
|-
 
|-
| 09:44
+
|07:50
| '''20''' as the value of '''age'''.
+
|Similarly instantiate the''' Person class''' using the''' Student class'''.
  
 
|-
 
|-
| 09:47
+
|07:55
| '''12005''' as the value of''' student Reg No.''' and '''A''' as the value of '''grade'''.
+
|This is represented as '''Person p2 equals new Student.'''
  
 
|-
 
|-
| 09:55
+
|08:01
| Now we can call the''' showBasicDetails() method '''using the '''object p2''' as '''p2.showBasicDetails()'''
+
|Now we are passing the values of different '''arguments'''.
  
 
|-
 
|-
| 10:04
+
|08:06
| We can also invoke the''' showDetails() method''' using the '''object p2''' as '''p2.showDetails()'''
+
|We can invoke the''' showBasicDetails() method '''and''' showDetails()''' '''method '''using the '''object''' as shown.
  
 
|-
 
|-
| 10:13
+
|08:15
| Now let us run this '''Demo''' program. So right click on the '''class Demo''' and then select '''Run as''' ->''' Java Application'''
+
| Now let us run this '''Demo''' program.  
 +
 
  
 
|-
 
|-
| 10:23
+
|08:18
| We can see the output with the basic employee details like''' name '''and''' age.'''
+
|So right click on the '''class Demo''' and then select '''Run as''' ->''' Java Application'''
  
 
|-
 
|-
| 10:29
+
| 08:25
| These are printed by '''showBasicDetails() method.'''  
+
| We can see the output with the basic employee details like''' name '''and''' age.'''
  
 
|-
 
|-
| 10:33
+
|08:31
| Other Employee details like''' employee ID '''and '''salary '''are printed by the''' showDetails() method'''.
+
|These are printed by '''showBasicDetails() method.'''
  
 
|-
 
|-
| 10:41
+
|08:35
| Similarly, the basic student details like '''name''' and '''age''' are printed by''' showBasicDetails() method.'''
+
|Other employee details like''' employee ID '''and '''salary '''are printed by the''' showDetails() method'''.
  
 
|-
 
|-
| 10:50
+
|08:43
| Other details of the student like '''Student register no '''and '''grade''' are printed by the''' showDetails() method'''.
+
|Similarly the basic student details like '''name''' and '''age''' are printed by''' showBasicDetails() method.'''
  
 
|-
 
|-
| 10:59
+
|08:52
 +
|Other details of the student like '''Student register number '''and '''grade''' are printed by the''' showDetails() method'''.
 +
 
 +
|-
 +
| 09:01
 
| This brings us to the end of this tutorial. Let us summarize.
 
| This brings us to the end of this tutorial. Let us summarize.
  
 
|-
 
|-
| 11:05
+
| 09:07
| In this tutorial we have learnt about
+
| In this tutorial we have learnt about '''Abstract Methods '''and''' Concrete Methods'''
  
* '''Abstract Methods '''and''' Concrete Methods'''
+
|-
* '''Abstract Classes '''and''' Concrete Classes '''and  
+
|09:14
* How to create and use''' Abstract Classes'''
+
| '''Abstract Classes '''and''' Concrete Classes '''and How to create and use''' Abstract Classes'''
  
 
|-
 
|-
| 11:19
+
| 09:21
| As an assignment- Create an '''abstract class Vehicle''' which contains an '''abstract method run()'''
+
| As an assignment Create an '''abstract class Vehicle''' which contains an '''abstract method''' '''run()'''
  
 
|-
 
|-
| 11:27
+
|09:29
| Create a '''subclass Car''' which extends the '''Vehicle class''' and implements the '''run method''' that prints '''“Car is running on 4 wheels”'''
+
| Create a'''subclass Car''' which extends the '''Vehicle class''' and implements the '''run method''' that prints '''“Car is running on 4 wheels”'''
  
 
|-
 
|-
| 11:37
+
|09:39
 
| Also create a'''subclass Bike''' which again extends the '''Vehicle class''' and implements the '''run method''' that prints '''“Bike is running on 2 wheels”'''
 
| Also create a'''subclass Bike''' which again extends the '''Vehicle class''' and implements the '''run method''' that prints '''“Bike is running on 2 wheels”'''
  
 
|-
 
|-
| 11:48
+
|09:50
| Also create a '''Demo class '''containing the''' main method''' to verify the results.
+
|Also create a '''Demo class '''containing the''' main method''' to verify the results.
  
 
|-
 
|-
| 11:54
+
| 09:56
| The video at the following link summarizes the''' '''Spoken Tutorial Project. Please download and watch it.
+
| The video at the following link summarizes the Spoken Tutorial Project. Please download and watch it.
  
 
|-
 
|-
| 12:02
+
| 10:03
| The Spoken Tutorial Project Team
+
| The Spoken Tutorial Project Team Conducts workshops using spoken tutorials and
  
* Conducts workshops using spoken tutorials
+
|-
* Gives certificates on passing the online tests
+
|10:09
 +
| Gives certificates on passing the online tests
  
 
|-
 
|-
| 12:11
+
|10:13
| For more details, please write to us.
+
|For more details, please write to us.
  
 
|-
 
|-
| 12:15
+
| 10:16
 
| Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
 
| Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
  
More information on this Mission is available at the link shown.
+
|-
 +
|10:23
 +
|More information on this Mission is available at the link shown.
  
 
|-
 
|-
| 12:26
+
| 10:28
| This script has been contributed by: Dept. of Information Technology, Amal Jyothi College of Engineering.
+
| This script has been contributed by:Dept. of Information Technology, Amal Jyothi College of Engineering.
  
 
+
|-
This is Priya from IIT Bombay signing off. Thank you for joining.
+
|10:35
 +
|This is Priya from IIT Bombay signing off. Thank you for joining.
  
 
|}
 
|}

Revision as of 15:16, 13 January 2017

Time
Narration
00:00 Welcome to the Spoken Tutorial on Abstract Classes.
00:05 In this tutorial we will learn about: Abstract Methods and Concrete Methods
00:12 Abstract Classes and Concrete Classes and
00:16 How to use Abstract Classes
00:18 For this tutorial, I am using
  • Ubuntu 12.04
  • JDK 1.7 and
  • Eclipse 4.3.1
00:28 To follow this tutorial, you should have knowledge of basics of Java and Eclipse IDE.
00:36 You should also have the knowledge of subclassing in Java.
00:40 If not, for relevant Java tutorials, please visit the link shown.
00:46 First we will see about Abstract Method.
00:50 An Abstract method is a method that is declared without implementation.
00:55 It is declared using abstract keyword.


00:59 There should not be opening and closing parenthesis for this method.
01:04 Let us understand the usage of Abstract class with a sample program.
01:09 Now we will switch to Eclipse and create a new project called AbstractDemo.
01:16 Inside this project we will create the necessary classes to demonstrate the usage of Abstract class.
01:24 Now, right click on src folder and click New-> Class.
01:30 Type the name of the class as Person and press Enter.
01:35 Now we will add the fields to represent the name and the age of the Person. Type String name semicolon.
01:44 Also type int age semicolon.
01:48 Now click on Source -> and select Generate constructor using fields.
01:55 Delete the super keyword from the generated code.
01:59 The constructor can initialise the values of name and age fields.
02:05 Next we will see about concrete method.


02:08 A Concrete method is completely implemented within the curly brackets.
02:14 We will add a concrete method to this class to print the name and age.
02:21 Type the following code as displayed on the screen.
02:25 This method showBasicDetails() illustrated here, is an example of concrete method.
02:32 Observe that this method is implemented completely.
02:36 Now we will add an abstract method to this class.
02:41 So type public void showDetails( ) semicolon.
02:46 An error comes up, since we have not yet added the abstract keyword.
02:51 So now add the keyword abstract.
02:55 Now we can see another error comes up.
02:58 This is because, abstract methods can be added only to abstract classes.
03:03 So now add the keyword abstract to the Person class to make it an abstract class.
03:10 The class Person illustrated here is an abstract class.


03:15 It contains an abstract method called showDetails().
03:20 The figure here represents an inheritance relation.
03:24 Here, the Person class is an abstract class.
03:29 The Employee class and the Student class are subclasses of the Person class.
03:35 These subclasses can provide their own different implementations.
03:40 These are done by showDetails( ) method present in the Person class.
03:45 For example: ShowDetails() Method in the Employee class prints the Employee ID and the Salary, where as ShowDetails() Method in the Student class prints the Student Register Number and Grade.
04:01 Then right-click on the default package and create another class called Employee.
04:07 Now to make this a subclass of Person class, type extends Person.
04:14 Now we can see an error comes up in the Eclipse IDE.
04:19 It indicates that, we should provide an implementation to the abstract method showDetails( ).
04:26 We will do it a little later.
04:28 Now create two fields to represent the employee id and employee salary.
04:34 So type String empid semicolon and int salary semicolon
04:42 Now click on Source-> and then select Generate constructor using fields.
04:49 This constructor can initialise the values of name, age, empid and salary.
04:56 Let us now define the showDetails method. So type public void showDetails( ).
05:04 Inside this method, we need to print the employee details.
05:09 Type the following code as displayed on the screen.
05:13 Note that the error disappears, once the showDetails() method is implemented.
05:19 Next we will see a Student class of the project.
05:23 I have already created a subclass called Student.
05:28 There are two fields in the Student class – register number and grade which represent student egister number and grade.
05:37 A constructor is also created inside this class.
05:42 This constructor can be used to initialize the values for name, age, register number and grade.
05:50 The showDetails method is also implemented in this class.
05:56 It prints the values of Student Register Number and grade
06:00 Now note that the Employee class has its own implementation of showDetails().
06:08 And the Student class has its own implementation of showDetails().
06:14 Now right-click on the default package.
06:17 Click on New-> Class and then type name as Demo.
06:23 Inside this class we will have the main method,
06:27 So type main and then press ctrl+space to generate the main method.
06:33 Now let us try to instantiate the Person class by typing Person p equals new Person.
06:42 Within brackets and double quotes type John and put a semicolon.
06:48 Now we can see an error. This is because the Person class is abstract and it cannot be instantiated.
06:58 Let's remove this line.
07:00 Type the following code as displayed on the screen.
07:04 Now let us instantiate the Person class using the Employee class as Person p1 equals new Employee.
07:14 In the first line, we are passing the values of different arguments.
07:19 John is passed as Employee name.
07:22 40 as the value of age.
07:25 E267 as the value of Employee ID and 10000 as the value of Employee salary.
07:33 Now we can invoke the concrete method in the Person class as p1.showBasicDetails()
07:41 We can also call the showDetails() method using the object p1 as p1.showDetails()
07:50 Similarly instantiate the Person class using the Student class.
07:55 This is represented as Person p2 equals new Student.
08:01 Now we are passing the values of different arguments.
08:06 We can invoke the showBasicDetails() method and showDetails() method using the object as shown.
08:15 Now let us run this Demo program.


08:18 So right click on the class Demo and then select Run as -> Java Application
08:25 We can see the output with the basic employee details like name and age.
08:31 These are printed by showBasicDetails() method.
08:35 Other employee details like employee ID and salary are printed by the showDetails() method.
08:43 Similarly the basic student details like name and age are printed by showBasicDetails() method.
08:52 Other details of the student like Student register number and grade are printed by the showDetails() method.
09:01 This brings us to the end of this tutorial. Let us summarize.
09:07 In this tutorial we have learnt about Abstract Methods and Concrete Methods
09:14 Abstract Classes and Concrete Classes and How to create and use Abstract Classes
09:21 As an assignment Create an abstract class Vehicle which contains an abstract method run()
09:29 Create asubclass Car which extends the Vehicle class and implements the run method that prints “Car is running on 4 wheels”
09:39 Also create asubclass Bike which again extends the Vehicle class and implements the run method that prints “Bike is running on 2 wheels”
09:50 Also create a Demo class containing the main method to verify the results.
09:56 The video at the following link summarizes the Spoken Tutorial Project. Please download and watch it.
10:03 The Spoken Tutorial Project Team Conducts workshops using spoken tutorials and
10:09 Gives certificates on passing the online tests
10:13 For more details, please write to us.
10:16 Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
10:23 More information on this Mission is available at the link shown.
10:28 This script has been contributed by:Dept. of Information Technology, Amal Jyothi College of Engineering.
10:35 This is Priya from IIT Bombay signing off. Thank you for joining.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Sandhya.np14