Java/C3/Calling-methods-of-the-superclass/English-timed

From Script | Spoken-Tutorial
Revision as of 11:59, 17 May 2017 by Sandhya.np14 (Talk | contribs)

Jump to: navigation, search


Time
Narration
00:01 Welcome to the spoken-tutorial on Calling methods of the super class.
00:07 In this tutorial, we will learn: * when to use the super keyword
00:13 * How to call methods of the super class
00:17 * How to invoke the constructor of the super class.
00:22 Here we are using:
  • Ubuntu Version 12.04
  • JDK 1.7
  • Eclipse 4.3.1
00:32 To follow this tutorial, you must have basic knowledge of Java and Eclipse IDE.
00:39 You must also have knowledge of subclassing and method overriding in Java.
00:45 If not, for relevant tutorials, please visit our website.
00:51 A subclass can use a superclass data or method using the super keyword.
00:58 The super keyword :
  • refers to the instance variable of the parent class.
  • is used to invoke parent class constructor.
  • is used to invoke parent class method.
01:13 Now, let us go to the IDE and to the project we created earlier.
01:19 Let us go to the Manager class.
01:22 Now, come to the getDetails() method.
01:26 In the return statement, let us remove Name and Email.
01:32 Now, let us come to the Employee class.
01:36 This is the parent class or super class.
01:41 We already have a getDetails() method here.
01:46 This method returns the name and email.
01:51 So, we can use this getDetails() method in the Manager class.
01:57 We will call getDetails() method from the Employee class, inside the Manager class.
02:04 So, come to the getDetails() method in the manager class.
02:10 Inside the return statement, type: super dot getDetails() plus slash n Manager of getDepartment().
02:22 Now, let me run the program.
02:25 We can see that we get the Manager details. Thus we can call the method of superclass inside the subclass.
02:36 Now let us come to the Employee class.
02:41 Let us include a constructor here.
02:44 So, inside the Employee class, type: public space Employee within brackets String name, String email_address .
02:59 Within curly brackets, type:

this dot name is equal to name semicolon this dot email_address is equal to email_address

03:17 Now, let us comment the setter and getter methods.
03:23 Inside the getDetails() method-

instead of getName, type name

instead of getEmail, type email_address.

03:37 A subclass inherits all of the methods and variables from a parent class.
03:44 Note that it does not inherit constructors.
03:49 But, constructors can call the non-private constructors of its superclass.
03:55 We do this using the keyword super from the child class constructor.
04:01 We will see that now.
04:04 For that, come to the Manager class. We will include a constructor here.
04:10 So, type: public space Manager within brackets String space name comma String space email underscore address comma String space dept .
04:30 Then, within curly brackets, type: super within brackets name, email underscore address semicolon.
04:44 Then type: department is equal to dept semicolon.
04:51 Here we will comment the setter and getter methods.
04:56 Then, in the getDetails() method type: department instead of getDepartment.
05:05 Now, come to the TestEmployee class.
05:09 Comment the call to the setter methods.
05:15 Now, inside the call to the Manager constructor type within quotes Nikkita Dinesh, abc@gmail.com, Accounts
05:32 Now, run the program.
05:35 We get the output as shown. We get the Manager details.
05:40 In this way, we can call the constructor of the super class.
05:45 In this tutorial we have learnt:

the super keyword calling the method of the super class and invoking constructor of super class

05:56 As an Assignment

Open the previous assignment. Call the Vehicle class run method in the Bike class.

06:04 The output should be:

The Vehicle is running. The Bike is running safely.

06:10 To know more about the Spoken Tutorial Project, Watch the video available at the following link
06:17 It summarizes the Spoken Tutorial project . If you do not have good bandwidth, you can download and watch it
06:26 The Spoken Tutorial Project Team

Conducts workshops using spoken tutorials Gives certificates for those who pass an online test For more details, please write to contact at spoken hyphen tutorial dot org

06:42 Spoken Tutorial Project is a part of the Talk to a Teacher project
06:46 It is supported by the National Mission on Education through ICT, MHRD, Government of India
06:54 More information on this Mission is available at http://spoken-tutorial.org/NMEICT- Intro
07:05 This is Arya Ratish from IIT Bombay signing off. Thanks for joining.

Contributors and Content Editors

Jyotisolanki, PoojaMoolya, Pratik kamble, Sandhya.np14