Opening Hours :7AM to 9PM
Super is a keyword in java language which is used in two different ways.
1.super.(dot)
2.super()
class Parent
{
int x=90;
}
class Child extends Parent
{
int x=30;
void show()
{
int x=10;
System.out.println(x);\\ local variable
System.out.println(this.x); \\ global variable
System.out.println(super.x); \\ parant class variable
}
}
class Main
{
public static void main(String args[])
{
Child c=new Child();
c.show();
}
}
class A
{
A(int x)
{
System.out.println("Parent constructor");
}
}
class B extends A
{
B(int x)
{
System.out.println("child constructor");
}
}
class M
{
public static void main(String args[])
{
B ob =new B(10);
}
}
class A
{
A(int x)
{
System.out.println("Parent constructor");
}
}
class B extends A
{
B(int x)
{
super(20);
System.out.println("child constructor");
}
}
class M
{
public static void main(String args[])
{
B ob =new B(10);
}
}