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...")
 
 
(4 intermediate revisions by 3 users not shown)
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'''
+
 
* '''JDK 1.7 '''and
+
'''Ubuntu 12.04'''
* '''Eclipse''' '''4.3.1'''
+
 
 +
'''JDK 1.7 '''and
 +
 
 +
'''Eclipse''' '''4.3.1'''
  
 
|-
 
|-
| 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:40
 +
|If not, for relevant''' Java '''tutorials, please visit the link shown.
  
 
|-
 
|-
| 00:46
+
|00:46
| First we will see about '''Abstract Method'''.
+
|First we will see about '''Abstract Method'''.
  
 
|-
 
|-
| 00:50
+
|00:50
| An '''Abstract method''' is a''' method''' that is declared without implementation.
+
| An '''Abstract method''' is a''' method''' that is declared without '''implementation'''.
  
 
|-
 
|-
 
| 00:55
 
| 00:55
| It is declared using''' abstract '''keyword. There should not be opening and closing parenthesis for this '''method'''.
+
|It is declared using''' abstract''' keyword.
  
 
|-
 
|-
| 01:04
+
| 00:59
| The''' method showDetails()''' illustrated here, is an example of''' abstract method'''.
+
|There should not be opening and closing parenthesis for this '''method'''.
  
 
|-
 
|-
| 01:10
+
|01:04
| Note that this '''method''' is declared using the''' abstract '''keyword, with no current implementation.
+
|Let us understand the usage of '''Abstract class '''with a sample program.
  
 
|-
 
|-
| 01:18
+
|01:09
| Next we will see about '''concrete method'''.
+
|Now we will switch to''' Eclipse''' and create a new '''project''' called '''AbstractDemo'''.
  
 
|-
 
|-
| 01:21
+
| 01:16
| A '''Concrete method''' is completely implemented within the curly brackets.
+
|Inside this '''project''', we will create the necessary '''classes''' to demonstrate the usage of''' Abstract class.'''
  
 
|-
 
|-
| 01:27
+
|01:24
| This method''' showBasicDetails()''' illustrated here is an example of '''concrete method'''.
+
|Now, right-click on '''src''' folder and click '''New > Class'''.
  
 
|-
 
|-
| 01:35
+
|01:30
| Observe that this '''method''' is implemented completely.
+
|Type the name of the '''class''' as '''Person''' and press '''Enter'''.
  
 
|-
 
|-
| 01:39
+
|01:35
| Now we will learn about '''abstract class''' with an example.
+
|Now we will add the '''field'''s to represent the name and the age of the''' Person'''. Type: ''' String name''' semicolon.  
  
 
|-
 
|-
| 01:44
+
|01:44
| An''' abstract class''' usually contains at least one''' abstract method'''.
+
|Also type: ''' int age''' semicolon.
  
 
|-
 
|-
| 01:49
+
|01:48
|   '''Abstract methods '''can be added only to '''abstract classes.'''
+
|Now click on''' Source''' and select''' Generate constructor using fields.'''
  
 
|-
 
|-
| 01:54
+
|01:55
| The '''class Person''' illustrated here is an''' abstract class.'''
+
|Delete the '''super''' keyword from the generated code.
  
 
|-
 
|-
| 01:59
+
|01:59
| It contains an''' abstract method''' called''' showDetails()'''.
+
|The '''constructor''' can initialise the values of '''name''' and '''age '''fields.
  
 
|-
 
|-
| 02:04
+
|02:05
| It can also contain '''variables''' and other '''concrete methods.'''
+
|Next we will see about '''concrete method'''.
  
 
|-
 
|-
| 02:09
+
|02:08
| The figure here represents an '''inheritance relation'''. Here, the''' Person class''' is an''' abstract class.'''
+
|A '''Concrete method''' is completely implemented within the curly brackets.
  
 
|-
 
|-
| 02:18
+
|02:14
| The''' Employee class''' and the '''Student class''' are '''subclasses''' of the''' Person class'''.
+
|We will add a''' concrete method''' to this '''class''' to print the name and age.  
  
 
|-
 
|-
| 02:24
+
|02:21
| These '''subclasses''' can provide their own different implementations.
+
|Type the following code as displayed on the screen.
  
 
|-
 
|-
| 02:29
+
|02:25
| These are done by''' showDetails( ) method''' present in the''' Person class.'''
+
|This method '''showBasicDetails()''' illustrated here, is an example of '''concrete method'''.
  
 
|-
 
|-
| 02:35
+
|02:32
| 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.'''
+
|Observe that this '''method''' is implemented completely.
  
 
|-
 
|-
| 02:49
+
|02:36
| A '''class''' is said to be a''' concrete class,''' if all the '''methods''' in that '''class''' are''' concrete methods'''.  
+
|Now we will add an '''abstract method''' to this '''class'''.
  
 
|-
 
|-
| 02:57
+
|02:41
| The '''class Employee''' illustrated here, is a''' concrete class'''.  All the '''methods''' inside this '''class''' including''' showDetails()''' are '''concrete'''.
+
|So, type: '''public void showDetails( )''' semicolon.
  
 
|-
 
|-
| 03:07
+
|02:46
| Let us understand the usage of '''Abstract class '''with a sample program.
+
|An error comes up, since we have not yet added the''' abstract  keyword. '''
  
 
|-
 
|-
| 03:12
+
|02:51
| Now we will switch to''' Eclipse''' and create a new '''project''' called '''AbstractDemo'''.
+
|So, now add the keyword '''abstract.'''
  
 
|-
 
|-
| 03:19
+
|02:55
| Inside this '''project''', we will create the necessary '''classes''' to demonstrate the usage of''' Abstract class.'''
+
|Now we can see another error comes up.
  
 
|-
 
|-
| 03:27
+
|02:58
| Now, right click on '''src''' folder and click '''new-'''> '''class'''.
+
|This is because, '''abstract methods''' can be added only to '''abstract classes'''.
  
 
|-
 
|-
| 03:33
+
|03:03
| Type the name of the '''class''' as '''Person''' and press '''Enter'''.
+
|So, now add the keyword '''abstract''' to the''' Person class '''to make it an''' abstract class.'''
  
 
|-
 
|-
| 03:38
+
|03:10
| Now we will add the fields to represent the name and age of the''' Person'''.
+
|The '''class Person''' illustrated here is an''' abstract class.'''
  
 
|-
 
|-
| 03:44
+
|03:15
| Type''' String name semicolon.''' Also type''' int age semicolon.'''
+
|It contains an''' abstract method''' called''' showDetails()'''.
  
 
|-
 
|-
| 03:51
+
|03:20
| Now click on''' source ->''' and select''' generate constructor using fields. '''
+
| The figure here represents an '''inheritance relation'''.
  
 
|-
 
|-
| 03:58
+
|03:24
| Delete the '''super '''keyword from the generated code.
+
|Here, the''' Person class''' is an''' abstract class.'''
  
 
|-
 
|-
| 04:02
+
|03:29
| The '''constructor''' can initialise the values of '''name''' and '''age '''fields.
+
|The''' Employee class''' and the '''Student class''' are '''subclasses''' of the''' Person class'''.
  
 
|-
 
|-
| 04:08
+
|03:35
| We will add a''' concrete method''' to this '''class''' to print the name and age.  
+
|These '''subclasses''' can provide their own different implementations.
  
 
|-
 
|-
| 04:14
+
|03:40
| So type '''public void showBasicDetails( )''' within '''brackets''' type, '''System.out.println''' within round brackets and within quotes type''' Name colon''' plus''' name semicolon'''
+
| These are done by''' showDetails( )''' method present in the''' Person class.'''
  
 
|-
 
|-
| 04:33
+
|03:45
| Also type '''System.out.println''' within round brackets and within quotes''' Age colon''' plus''' age semicolon'''
+
|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:46
+
| 04:01
| Now we will add an '''abstract method''' to this '''class'''. So type '''public void showDetails( ) semicolon'''
+
| Then right-click on the '''default package''' and create another''' class''' called''' Employee.'''
  
 
|-
 
|-
| 04:56
+
|04:07
| An error comes up, since we have not yet added the''' abstract '''keyword.  
+
|Now to make this a '''subclass''' of '''Person class,''' type: ''' extends Person'''.
  
 
|-
 
|-
| 05:01
+
| 04:14
| So now, add the keyword '''abstract.'''
+
| Now, we can see an error comes up in the '''Eclipse IDE.'''
  
 
|-
 
|-
| 05:04
+
|04:19
| Now we can see, another error comes up. This is because, '''abstract methods''' can be added only to '''abstract classes'''.
+
|It indicates that we should provide an '''implementation''' to the '''abstract method showDetails( )'''.
  
 
|-
 
|-
| 05:13
+
|04:26
| So now, add the keyword''' abstract''' to the''' Person class '''to make it an''' abstract class.'''
+
|We will do it a little later.
  
 
|-
 
|-
| 05:20
+
| 04:28
| Then right click on the '''default package''' and create another''' class''' called''' Employee.'''
+
| Now create two '''field'''s to represent the '''employee id''' and '''employee salary'''.
  
 
|-
 
|-
| 05:26
+
|04:34
| Now to make this a '''subclass''' of '''Person class, '''type''' extends Person'''.
+
|So, type: ''' String empid''' semicolon and''' int salary''' semicolon.
  
 
|-
 
|-
| 05:34
+
|04:42
| Now we can see an error comes up in the '''Eclipse IDE.'''
+
|Now click on '''Source''' and then select''' Generate constructor using fields.'''  
  
 
|-
 
|-
| 05:38
+
|04:49
| It indicates that, we should provide an implementation to the '''abstract method showDetails( )'''.
+
|This '''constructor''' can initialize the values of '''name, age, empid '''and''' salary'''.
We will do it a little later.
+
  
 
|-
 
|-
| 05:48
+
| 04:56
| Now create two fields to represent the '''employee id''' and '''employee salary'''.
+
| Let us now define the''' showDetails method'''. So, type:''' public void showDetails( ).'''
  
 
|-
 
|-
| 05:54
+
|05:04
| So type ''' String empid semicolon''' and''' int salary semicolon'''
+
|Inside this '''method''', we need to print the employee details.
  
 
|-
 
|-
| 06:01
+
|05:09
| Now click on '''source'''-> and then select''' generate constructor using fields.'''
+
|Type the following code as displayed on the screen.  
  
 
|-
 
|-
| 06:08
+
|05:13
| This '''constructor''' can initialise the values of '''name, age, empid '''and''' salary'''.
+
|Note that the error disappears, once the '''showDetails() method''' is implemented.
  
 
|-
 
|-
| 06:15
+
|05:19
| Let us now define the''' showDetails method'''. So type''' public void showDetails( )'''
+
|Next we will see a '''Student class''' of the '''project'''.
  
 
|-
 
|-
| 06:23
+
|05:23
| Inside this '''method''', we need to print the employee details.  
+
|I have already created a '''subclass''' called''' Student'''.
  
 
|-
 
|-
| 06:27
+
|05:28
| So type '''System.out.println''' within quotes''' Emp id colon''' plus''' empid semicolon'''
+
| There are two fields in the '''Student class – register number''' and''' grade''' which represent student register number and grade.
  
 
|-
 
|-
| 06:38
+
| 05:37
| '''System.out.println''' within quotes''' Salary colon''' plus''' salary semicolon'''
+
| A '''constructor''' is also created inside this '''class'''.
  
 
|-
 
|-
| 06:47
+
|05:42
| Note that the error disappears, once the '''showDetails() method''' is implemented.
+
|This '''constructor''' can be used to initialize the values for''' name, age, register number '''and''' grade.'''
  
 
|-
 
|-
| 06:54
+
| 05:50
| Next we will see a '''Student class''' of the '''project'''.
+
| The''' showDetails method''' is also implemented in this '''class'''.  
  
 
|-
 
|-
| 06:57
+
|05:56
| I have already created a '''subclass''' called''' Student'''.
+
|It prints the values of''' Student Register Number''' and''' grade'''.
  
 
|-
 
|-
| 07:02
+
| 06:00
| There are two fields in the '''Student class, regno (register number) ''' and''' grade''' which represent '''student reg. no (register number)''' and '''grade'''.
+
| Now note that the''' Employee class''' has its own implementation of''' showDetails().'''
  
 
|-
 
|-
| 07:11
+
|06:08
| A '''constructor''' is also created inside this '''class'''. This '''constructor''' can be used to initialize the values for''' name, age, register number '''and''' grade.'''
+
|And the''' Student class''' has its own implementation of''' showDetails().'''
  
 
|-
 
|-
| 07:24
+
| 06:14
| The''' showDetails method''' is also implemented in this '''class'''.  It prints the values of''' Student Reg. Number''' and''' grade'''
+
| Now right-click on the '''default package.'''  
  
 
|-
 
|-
| 07:34
+
|06:17
| Now note that the''' Employee class''' has its own implementation of''' showDetails().'''
+
|Click on '''New''' > '''Class''' and then type name as''' Demo. '''
  
 
|-
 
|-
| 07:42
+
|06:23
| And the''' Student class''' has its own implementation of''' showDetails().'''
+
|Inside this '''class''', we will have the '''main''' method.
  
 
|-
 
|-
| 07:48
+
|06:27
| Now right click on the '''default package.''' Click on '''new'''-> '''class''' and then type name as''' Demo.'''
+
|So, type '''main''' and then press '''ctrl+space''' to generate the''' main''' method.
  
 
|-
 
|-
| 07:57
+
| 06:33
| Inside this '''class''', we will have the '''main method''', So type '''main''' and then press '''Ctrl space''' to generate the''' main method.'''
+
| Now let us try to instantiate the''' Person class''' by typing '''Person p equals new Person.'''
  
 
|-
 
|-
| 08:08
+
|06:42
| Now let us try to instantiate the''' Person class''' by typing '''Person p equals new Person.'''
+
|Within brackets and double quotes type '''John''' and put a semicolon.
  
 
|-
 
|-
| 08:16
+
|06:48
| Within brackets and double quotes, type '''John''' and put a '''semicolon'''.
+
|Now we can see an error. This is because the''' Person class''' is '''abstract''' and it cannot be instantiated.
  
 
|-
 
|-
| 08:23
+
|06:58
| Now we can see an error. This is because the''' Person class''' is '''abstract''' and it cannot be instantiated. Let's remove this line.
+
|Let's remove this line.
  
 
|-
 
|-
| 08:34
+
| 07:00
| Type the following code as displayed on the screen.
+
| Type the following code as displayed on the screen.
  
 
|-
 
|-
| 08:38
+
|07:04
| Now let us instantiate the''' Person class''' using the''' Employee class''' as '''Person p1 equals new Employee.'''
+
|Now, let us instantiate the''' Person class''' using the''' Employee class''' as '''Person p1 equals new Employee.'''
  
 
|-
 
|-
| 08:48
+
|07:14
| In the first line, we are passing the values of different '''arguments'''.
+
|In the first line, we are passing the values of different arguments.
 
+
*'''John''' is passed as '''Employee name''',
+
  
 
|-
 
|-
| 08:57
+
|07:19
| '''40''' as the value of '''age. E267''' as the value of '''Employee ID''' and
+
|'''John''' is passed as '''Employee name'''.
  
 
|-
 
|-
| 09:04
+
|07:22
| '''10000''' as the value of '''Employee salary.'''
+
|'''40''' as the value of '''age.'''
  
 
|-
 
|-
| 09:07
+
|07:25
| Now we can invoke the '''concrete method''' in the '''Person class''' as '''p1.showBasicDetails()'''
+
|'''E267''' as the value of '''Employee ID''' and '''10000''' as the value of '''Employee salary.'''
  
 
|-
 
|-
| 09:16
+
|07:33
| We can also call the''' showDetails() method''' using the '''object p1''' as '''p1.showDetails()'''
+
|Now we can invoke the '''concrete method''' in the '''Person class''' as '''p1.showBasicDetails()'''.
  
 
|-
 
|-
| 09:24
+
|07:41
| Similarly, instantiate the''' Person class''' using the''' Student class'''. This is represented as '''Person p2 equals new Student.'''
+
|We can also call the''' showDetails() method''' using the '''object p1''' as '''p1.showDetails()'''.
  
 
|-
 
|-
| 09:35
+
|07:50
| Now we are passing the values of different '''arguments'''.
+
|Similarly instantiate the''' Person class''' using the''' Student class'''.
 
+
'''Hari''' is passed as the value of''' student name''',
+
  
 
|-
 
|-
| 09:44
+
|07:55
| '''20''' as the value of '''age'''.
+
|This is represented as '''Person p2 equals new Student.'''
  
 
|-
 
|-
| 09:47
+
|08:01
| '''12005''' as the value of''' student Reg No.''' and '''A''' as the value of '''grade'''.
+
|Now we are passing the values of different '''arguments'''.
  
 
|-
 
|-
| 09:55
+
|08:06
| Now we can call the''' showBasicDetails() method '''using the '''object p2''' as '''p2.showBasicDetails()'''
+
|We can invoke the''' showBasicDetails() method '''and''' showDetails()''' method using the '''object''' as shown.
  
 
|-
 
|-
| 10:04
+
|08:15
| We can also invoke the''' showDetails() method''' using the '''object p2''' as '''p2.showDetails()'''
+
| Now let us '''run''' this '''Demo''' program.  
  
 
|-
 
|-
| 10:13
+
|08:18
| Now let us run this '''Demo''' program. So right click on the '''class Demo''' and then select '''Run as''' ->''' Java Application'''
+
|So, right-click on the '''class Demo''' and then select '''Run as''' >''' Java Application'''.
  
 
|-
 
|-
| 10:23
+
| 08:25
| We can see the output with the basic employee details like''' name '''and''' age.'''
+
| We can see the output with the basic employee details like''' name '''and''' age.'''
  
 
|-
 
|-
| 10:29
+
|08:31
| These are printed by '''showBasicDetails() method.'''  
+
|These are printed by '''showBasicDetails()''' method.
  
 
|-
 
|-
| 10:33
+
|08:35
| Other Employee details like''' employee ID '''and '''salary '''are printed by the''' showDetails() method'''.
+
|Other employee details like''' employee ID '''and '''salary '''are printed by the''' showDetails()''' method.
  
 
|-
 
|-
| 10:41
+
|08:43
| Similarly, the basic student details like '''name''' and '''age''' are printed by''' showBasicDetails() method.'''
+
|Similarly the basic student details like '''name''' and '''age''' are printed by''' showBasicDetails()''' method.
  
 
|-
 
|-
| 10:50
+
|08:52
| Other details of the student like '''Student register no '''and '''grade''' are printed by the''' showDetails() method'''.
+
|Other details of the student like '''Student register number '''and '''grade''' are printed by the''' showDetails()''' method.
  
 
|-
 
|-
| 10:59
+
| 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.
  
 
|}
 
|}

Latest revision as of 17:33, 24 April 2019

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 initialize 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 register 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