AI May 15, 2023 5 min read

Module 26: Super Keyword

BR

Bhargava Ram Pantina

Web Developer & AI Enthusiast

🧭 What is the super Keyword?

The super keyword in Java is a reference variable used to refer to the immediate parent class object. It is primarily used in inheritance scenarios to access the parent class members.

✨ Use Cases of super Keyword

  • To call the parent class constructor
  • To access parent class methods that are overridden
  • To access parent class variables when they are hidden

📘 Example: Using super

                    class Animal {
                      String color = "white";
                    
                      void eat() {
                        System.out.println("Animal eats food");
                      }
                    }
                    
                    class Dog extends Animal {
                      String color = "black";
                    
                      void printColor() {
                        System.out.println(super.color);  // accesses parent class variable
                      }
                    
                      void eat() {
                        System.out.println("Dog eats bones");
                      }
                    
                      void work() {
                        super.eat();  // calls parent class method
                      }
                    }
                    
                    public class Main {
                      public static void main(String[] args) {
                        Dog d = new Dog();
                        d.printColor();  // Output: white
                        d.work();        // Output: Animal eats food
                      }
                    }
Artificial Intelligence Web Development Technology Trends Machine Learning UX Design

Share this article

About the Author

BR

Bhargava Ram Pantina

Bhargava Ram is a web developer and AI enthusiast with over 8 years of experience in the tech industry. He specializes in creating innovative web solutions that leverage the latest technologies to solve real-world problems.

Related Articles

AI Mar 15, 2023

Implementing ChatGPT in Your Web Application: A Step-by-Step Tutorial

Learn how to integrate OpenAI's ChatGPT into your web application to create intelligent chatbots and enhance user interactions.

Read More →
Web Development Apr 22, 2023

Building Accessible Web Forms: A Complete Guide

Learn how to create web forms that are accessible to all users, including those with disabilities. This comprehensive guide covers ARIA attributes, keyboard navigation, and more.

Read More →

Subscribe to My Newsletter

Get the latest articles and resources delivered straight to your inbox.

No spam, just valuable content. Unsubscribe anytime.