Course Content

Course Content

Description

Super keyword at Constructor Level

In our previous video we have seen that what are This and Super keyword in Java programming language. In this video we are going to know about how Super keyword can work at Constructor level in Java with various examples.

Example :
class Employee
{
Employee ()
{
System.out.println("Employee class Constructor");
}
}
class HR1 extends Employee
{
HR1 ()
{
super(): //will invoke or call parent class constructor System.out.println("HR class Constructor");
}
}
class cons
{
public static void main (String[] args)
{
HR1 obj=new HR1();
}
}
Output :
Employee class Constructor
HR class Constructor

The Final keyword in Java is used to restrict the user in using a variable/method/class. Final can be Variable, Method, & Class.

The Final keyword in Java programming has three different uses, one is to create constants, second one is to prevent inheritance, and last one is to prevent methods from being overridden.

If you make any variable as final, you cannot change the value of variable. It will be constant.
Example :
class memo
{
public static void main (String args [])
{
final int i=20;
System.out.println(i);
}
}
Output :
20

If you make any method as final, you cannot override it.
Example :
class Bike
{
final void run ()
{
System.out.println ("running"):
}
class car extends Bike
{
void run()
{
System.out.println("running safely with 100kmph");
}
public static void main (String args[])
{
Honda h= now Honda();
h.run();
}
}
Output :
ERROR (you cannot override it)

If you make any class as final, you cannot extend it.
Example :
final class Bike
{
}
class car1 extends Bike
{
void run ()
{
System.out.println ("running safely with 100kmph");
}
public static void main (String args[])
{
car1 c= new car1 ();
c.run();
}
}
Output :
ERROR (cannot inherit from final Bike class car1 extends Bike)

So, this is how Super keyword work at Constructor level in Java programming language. In the next video of this ongoing Core Java course we will see Object Wrapper class in Java with example.

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere