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 :: java lambda function 
Java :: generic array creation java 
Java :: class syntax in java 
Java :: java abstract class 
Java :: ascii values to display certain characters in java 
Java :: @entity annotation in spring boot 
Java :: java tutorialspoint 
Java :: mp3 player java 
Java :: how to make 2d array of strings in java 
Java :: finding min and max from given number in java 
Java :: button event 
Java :: number of matches regex java 
Java :: how to create a derived class in Java 
Java :: input 3 int 1 line in java 
Java :: how to convert integer to list in python 
Java :: java 8 list to map with occurrences 
Java :: interact with databse java 
Sql :: reset ids in mysql 
Sql :: sql find text in sp 
Sql :: sql finding longest and shortest names in a fleld 
Sql :: mysql change user password 
Sql :: refresh postgres config 
Sql :: too many connections mysql 
Sql :: sql drop procedure if exists 
Sql :: pl sql escape & 
Sql :: oracle list functions 
Sql :: oracle all_source package body 
Sql :: get the list of all tables in sql server 
Sql :: mysql check table exists 
Sql :: oracle first and last day of previous month 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =