ErrorException Message: Argument 2 passed to WP_Translation_Controller::load_file() must be of the type string, null given, called in /home3/equicklearning/public_html/wp-includes/l10n.php on line 838
https://www.equicklearning.com/wp-content/plugins/dmca-badge/libraries/sidecar/classes/ Super Keyword in Java in Hindi - Equick Learning

Super Keyword in Java in Hindi

Super Keyword in Java in Hindi

Java के अंतर्गत Super Keyword एक reference variable है, जिसका प्रयोग parent class का उल्लेख अथवा Refer करने के लिये किया जाता है । Super Keyword को निम्नलिखित अस्थितियो में प्रयोग किया जाता है-

-> इसका प्रयोग Sub-Class के members को super-class के members से अलग करने के लिए किया जाता है, यदि उनका नाम same है तो ।

-> इनका प्रयोग sub-class से super-class के constructor को call करने के लिए किया जाता है ।

आइए इन दोनो के बारे में विस्त्रित जानकारी प्राप्त करते हैं-

यदि कोई एक class किसी अन्य class के गुणो को inherit करती है और यदि super-class और sub-class दोनो के members के नाम समान हैं, तब super keyword दोनो के variables और methods में निम्न्लिखित रुप से अंतर किया जा सकता है, और super-class के members को refer अलग से किया जा सकता है ।

super keyword in java

दोस्तो, आईए इसे एक प्रोग्राम की सहायता से समझते है-

 

class parent_super
{
int x=10;
public void display() //show method of super_class
{
System.out.println("This is the method of superclass");
}
}
public class child_class extends parent_super
{
int x=15;
public void display() //show method of sub_class
{
System.out.println("This is the method of subclass");
}
}
public void my_method()
{
child_class sub=new child_class();
System.out.println("Value of the variable named num in super class:"+super.x);
System.out.println("Value of the variable named num in sub class:"+sub.x);
}
public static void main(String[] args)
{
child_sub obj=new child_sub();
obj.supermethod();
}

 

Output-

 

This is super class's method.
This is sub class's method.
Value of variable of super class:10
Value of variable of subclass:15

 

ऊपर दिए गए program में हमारे पास दो classes हैं parent_super और child_sub और दोनो ही classes में same method show() को विभिन्न रूप में परिभािषित किया गया है, और x एक variable भी दोनो classes में विभिन्न मान के साथ परिभाशित किया गया है ।

हमने super keyword की सहायता से parent_super के method और variable दोनो को access कर लिया है । यदि हम super keyword का प्रयोग न करते तो same name होने के कारण केवल child_sub class के method और variable को access कर पाते ।

Uses of Super Keyword

  1. “Super” keyword will be wont to refer to immediate parent class instance variable.
  2. “Super” keyword will be wont to invoke immediate parent class method.
  3. super() will be wont to invoke immediate parent class constructor.

1. “Super” keyword will be wont to refer to immediate parent class instance variable

 

class A
{
int i=0;
}
class B extends A
{
int i=20;
void show(int i)
{
System.out.println(i);
System.out.println();
System.out.println();
}
public static void main(String[] args)
{
B ob=new B();
ob.show(30);
}
}
}

 


Output-

 

30
20
10

 

2. “Super” keyword will be wont to invoke immediate parent class method.

 

class A
{
void m1()
{
System.out.println("I'm in class A");
}
}
class B extends A
{
void m1()
{
System.out.println("I'm in class B");
}
void show()
{
m1();
super.m1();
}
public static void main(String[] args)
{
B ob=new B();
ob.show();
}
}

 

Output-

 

I'm in class B
I'm in class A

 

3. super() will be wont to invoke immediate parent class constructor.

 

class A
{
A()
{
System.out.println("I'm in class A");
}
}
class B extends A
{
B()
{
super();
System.out.println("I'm in class B");
}
public static void main(String[] args)
{
B ob=new B();
}
}

 

Output-

 

I'm in class A
I'm in class B

 

Author's Choice

PHP library to retrieve an Instagram profile feed

PHP library to retrieve an Instagram profile feed, embed the feed of your authorized Instagram accounts on your website. The library uses the Instagram...

Best eCommerce ad Platforms in 2023

On this weblog, we'll focus on the very best e-commerce advert platforms in 2023 to develop your small business and in addition I'll share...

5 Ways ML Testing Will Reshape the Data Science Career

The field of data science has seen a lot of changes in recent years - machines are used for many tasks that humans traditionally...

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here