Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

what is super in java

// to access a property 'num' from SuperClass:
super.num //or
((SuperClass)this).num
// to run the constructor of SuperClass: 
super()
Comment

Java super Keyword

class Animal { // Superclass (parent)
  public void animalSound() {
    System.out.println("The animal makes a sound");
  }
}

class Dog extends Animal { // Subclass (child)
  public void animalSound() {
    super.animalSound(); // Call the superclass method
    System.out.println("The dog says: bow wow");
  }
}

public class Main {
  public static void main(String args[]) {
    Animal myDog = new Dog(); // Create a Dog object
    myDog.animalSound(); // Call the method on the Dog object
  }
}
Comment

using super in Java

class Shape {
	public void draw() {
		System.out.println("Shape draw.");
	}
}
class Circle extends Shape {
	@Override
	public void draw() {
		System.out.println("Circle draw.");
		super.draw(); // Access parent's version of draw
	}
}
public class Main {
	public static void main(String[] args) {
		Circle c = new Circle();
		// The below prints: 
		// Circle draw.
		// Shape draw.
		c.draw();
	}	
}
Comment

Java Use of super Keyword

class Animal {
   public void displayInfo() {
      System.out.println("I am an animal.");
   }
}

class Dog extends Animal {
   public void displayInfo() {
      super.displayInfo();
      System.out.println("I am a dog.");
   }
}

class Main {
   public static void main(String[] args) {
      Dog d1 = new Dog();
      d1.displayInfo();
   }
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to find the largest number in java 
Java :: java difference hashmap hashtable 
Java :: get data from database sqlite android 
Java :: reverse negative number 
Java :: java hashmap time complexity 
Java :: Employee Java. 
Java :: class, interface, or enum expected java 
Java :: java ceil 
Java :: Java Exception handling using Java throw 
Java :: arraylist 
Java :: how to output in java 
Java :: Java Create an InputStream 
Java :: java check if int 
Java :: java parse json to class 
Java :: java string vers int 
Java :: Java LogManager 
Java :: how to find armstrong numbers in java 
Java :: color class android 
Java :: java static variable 
Java :: change text size java 
Java :: MyLinkedList 
Java :: hasNext for scanner class java 
Java :: could not find java in a java_home at /opt/java/openjdk/bin/java docker sonarqube 
Java :: video compression with java 
Java :: Task :run FAILED Error: Could not find or load main class Caused by: java.lang.ClassNotFoundException: 
Java :: date to yyMMdd conversion 
Java :: how to develop web apps using java 
Java :: String Reverse Program in Java. 
Java :: vue input pre initial value 
Java :: Big decimal example 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =