Java/C3/Calling-methods-of-the-superclass/English
Title of script: Calling methods of the super class
Author: Arya Ratish
Keywords: super keyword, video tutorial, Java, Eclipse IDE
|
|
Slide 1 | Welcome to the spoken-tutorial on Calling methods of the super class. |
Slide 2 | In this tutorial we will learn :
|
Slide 3
Software Requirements |
Here we are using
|
Slide 4
Prerequisites |
To follow this tutorial, you must have basic knowledge of Java and Eclipse IDE.
|
Slide 5
Using super keyword
|
A subclass can use a superclass data or method using the super keyword. |
Slide 6
Using super keyword |
The super keyword :
|
Go to the IDE. | Now, let us go to the IDE and to the project we created earlier. |
Go to the Manager class. | Let us go to the Manager class. |
Come to the getDetails() method.
Remove Name and Email. |
Now, come to the getDetails() method.
|
Go to the Employee class.
|
Let us come to the Employee class.
|
Highlight the return statement. | This method returns the name and email. |
So, we can use the getDetails() method in the Manager class. | |
Go to the Manager class. | We will come to the Manager class. |
We will call getDetails() method from the Employee class, inside the Manager class. | |
Come to the getDetails() method. | So, come to the getDetails() method. |
Inside the return statement type super dot getDetails(). | Inside the return statement type
super dot getDetails() plus within double quotes Manager of plus department. |
Run the program. | Now, let me run the program again. |
Highlight the output. | We can see that we get the Manager details. |
Come back to the Employee class. | Come back to the Employee class. |
Let us include a constructor here. | |
Type
public Employee(String name, String email_address) { this.name=name; this.email_address=email_address; } |
So inside the Employee class, type
this dot email_address is equal to email_address semicolon
|
Also comment the setter and getter methods. | |
Type
{
} |
Inside the getDetails() method,
|
A subclass inherits all of the methods and variables from a parent class.
| |
But, constructors can call the non-private constructors of its superclass.
| |
Come to the Manager class. | We will see that now.
|
Type
super(name,email_address); department=dept; } |
Type
|
Here we will comment the setter and getter methods. | |
Type
public String getDetails() { return ( super.getDetails()+"\n" +"Manager of: " + department); } |
Then, in the getDetails() method type department instead of getDepartment. |
Now, come to the TestEmployee class. | |
Comment manager.setName("Nikkita Dinesh");
manager.setEmail("abc@gmail.com"); manager.setDepartment("Accounts"); |
Comment the call to the setter methods. |
Type
Manager manager= new Manager("Nikkita Dinesh", "abc@gmail.com", "Accounts"); |
Now, inside the call to the Manager constructor type within quotes Nikkita Dinesh, abc@gmail.com, Accounts |
Now, run the program. | |
Highlight
Email: abc@gmail.com Manager of: Accounts
|
We get the output as shown.
We get the Manager details. |
In this way, we can call the constructor of the super class. | |
Slide 7
Summary |
In this tutorial we have learnt:
|
Slide 8
|
Assignment
|
Slide 9
|
* Watch the video available at the following link
|
Slide 10
About Spoken Tutorial workshops |
The Spoken Tutorial Project Team
|
Slide 11
Acknowledgement |
Spoken Tutorial Project is a part of the Talk to a Teacher project
This is Arya Ratish from IIT Bombay signing off.
|