// Super keyword is used to:
// Call super class methods
// Call super class constructors
// super.methodName() can be call anywhere from the subClass
// it do not have to be first statement
public class SuperDemo {
public static void main(String[] args)
{
Student s = new Student();
s.printInfo();
}
}
class Person
{
String name = "Shyam";
String age = "22";
public void printInfo()
{
System.out.println("Name is : "+ name + " and my age is : "+ age);
}
}
class Student extends Person
{
int mark = 70;
public void printInfo()
{
System.out.println("Exam mark is: "+ mark);
super.printInfo();
}
}

No comments:
Post a Comment