Modal Box

super in java

 Super keyword is used to call super class constructor or the super class function.
 When we use super to call the super class constructor, then it should be the first statement.
class Person
{
  String name=null;
  int age=0;
  Person(String n, int a)
  {
    name=n;
    age=a;
  }
void display() { System.out.println("name=" +name); } }

class Student extends Person {
int rollNo=0; String course=null; Student(String n, int a, String c, int r) { super(n,a); rollNo=r; course=c; } public void display() { super.display(); System.out.println("Course= "+course+"Roll No="+rollNo); } }

class CheckMain {
public static void main(String args[]) {
Person p= new Person("Rahul",25); p.display(); Student s1= new Student("John",20,"BCA",4093); s1.display(); // variable may be passed instead of static value
} }

Video/ C Introduction

Watch video in full size
Wordpress Social Share Plugin powered by Ultimatelysocial