Wednesday, May 15, 2024
HomeJavaImplement Interface utilizing Summary Class in Java

Implement Interface utilizing Summary Class in Java


Java Interface, Abstract Class, Java Career, Java Prep, Java Preparation, Java Tutorial and Materials, Java Certification, Java Jobs

Interface comprises solely summary strategies that may’t be instantiated and it’s declared by key phrase interface. A category that’s declared with the summary key phrase is called an summary class in Java. This can be a class that often comprises at the least one summary technique which might’t be instantiated and It’s also potential for the category to haven’t any strategies in any respect. The occasion of an summary class can’t be created.

Now as all strategies in an interface are summary strategies subsequently we will implement it utilizing Summary Class.

1. Let’s create an Interface at first:

// creating an interface named ORACLEJAVACERTIFIED 

interface ORACLEJAVACERTIFIED { 

void learnCoding(); 

void learnProgrammingLanguage(); 

void contribute(); 

}

Right here the three  non-implemented strategies are the summary strategies

2. Now let’s implement the interface in an Summary class named Pupil:

// creating an summary class named Pupil which is 

// implementing the interface,ORACLEJAVACERTIFIED 

summary class Pupil implements ORACLEJAVACERTIFIED { 

// Overriding two strategies of the interfacem,ORACLEJAVACERTIFIED

@Override public void learnCoding() 

System.out.println( 

“Let’s make coding a behavior with ORACLEJAVACERTIFIED”); 

@Override public void learnProgrammingLanguage() 

System.out.println( 

“Let’s grasp all fundamentals of java with the assistance of ORACLEJAVACERTIFIED”); 

}

Right here we’ve overridden two summary strategies of the interface ORACLEJAVACERTIFIED.

3. Now let’s create a category JAVA which extends the summary class, Pupil:

As beforehand talked about, we will’t create an occasion of our summary class subsequently we have to make a non-abstract class.

// creating an non-abstract class 

// JAVA which is extending Pupil 

class JAVA extends Pupil { 

// overriding the remaining technique of the interface,ORACLEJAVACERTIFIED 

@Override public void contribute() 

System.out.println( 

“Now let’s assist others by contributing in ORACLEJAVACERTIFIED”); 

}

Right here we’ve overridden the remaining technique of the interface ORACLEJAVACERTIFIED.

Under is the general implementation of the issue assertion:

// Implemention of Interface utilizing Summary Class in Java 

// Interface ORACLEJAVACERTIFIED 

interface ORACLEJAVACERTIFIED { 

void learnCoding(); 

void learnProgrammingLanguage(); 

void contribute(); 

// Summary class Pupil implementing from ORACLEJAVACERTIFIED interface 

summary class Pupil implements ORACLEJAVACERTIFIED { 

// Overriding the strategies 

@Override public void learnCoding() 

System.out.println( 

“Let’s make coding a behavior with ORACLEJAVACERTIFIED”); 

@Override public void learnProgrammingLanguage() 

System.out.println( 

“Let’s grasp all fundamentals of java with the assistance of ORACLEJAVACERTIFIED”); 

// Lengthen the JAVA class by Pupil summary class 

class JAVA extends Pupil { 

@Override public void contribute() 

System.out.println( 

“Now let’s assist others by contributing in ORACLEJAVACERTIFIED”); 

// Driver code 

public class Fundamental { 

public static void principal(String[] args) 

// New JAVA object is created 

JAVA oraclejavacertifiedStudent = new JAVA(); 

// Calls to the a number of features 

oraclejavacertifiedStudent.learnCoding(); 

oraclejavacertifiedStudent.learnProgrammingLanguage(); 

oraclejavacertifiedStudent.contribute(); 

}

Output:

Let’s make coding a behavior with ORACLEJAVACERTIFIED

Let’s grasp all fundamentals of java with the assistance of ORACLEJAVACERTIFIED

Now let’s assist others by contributing in ORACLEJAVACERTIFIED

Supply: geeksforgeeks.org

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments