Program to implement the Multiple Inheritance (Exam Interface, Student & Result classes)

Interface looks like class but it is not a class. An interface can have methods and variables just like the class but the methods declared in interface are by default abstract (only method signature, no body). Also, the variables declared in an interface are public, static & final by default. The interface in java is a mechanism to achieve fully abstraction.

The class that implements interface must implement all the methods of that interface. Also, java programming language does not support multiple inheritance, using interfaces we can achieve this as a class can implement more than one interfaces. It cannot be instantiated just like abstract class. To achieve multiple inheritance in Java you have to use interface. The syntax for declaring interface is given below:
interface <interface-name> {
    // variable declarations
 // Method declarations (no implementation)
}

The implements keyword is used to for implementing interface and extends keyword is used to extend the class. The syntax for extending class and implementing interface is:
class <subclass-name> extends <superclass-name> implements <interface-name> {

 // Body of subclass
}












In this program, we have achieved multiple inheritance using interface. We have created an interface Exam which has one method Percent_cal( ) without implementation (body). Then we declare the class Student having data members name, roll_no, marks1, marks2 and method show( ). In class Result we have extended Student class and implemented interface Exam interface as shown in program.


PROGRAM
/* Program to implement the Multiple Inheritance */

interface Exam {
 
 void Percent_cal();
}

class Student {
 
 String name;
 int roll_no, Marks1, Marks2;
 Student(String n, int rn, int m1, int m2) {
  
  name = n;
  roll_no = rn;
  Marks1 = m1;
  Marks2 = m2;
 }
 
 void show() {
  
  System.out.println("Student Name : "+name);
  System.out.println("Roll no : "+roll_no);
  System.out.println("Marks1 : "+Marks1);
  System.out.println("Marks2 : "+Marks2);
 }
}

class Result extends Student implements Exam {
 
 float per;
 Result(String n,int rn,int m1,int m2) {
  
  super(n,rn,m1,m2);
 }
 
 public void Percent_cal() {
  
  int tot = Marks1 + Marks2;
  per = (float)tot / 2;
 }
 
 void display() {
  
  show();
  System.out.println("Percentage = "+per);
 } 
 
}

public class StudentDetails {
 
 public static void main (String[] args) {
  
  Result r = new Result("Aashish",11,75,95);
  r.Percent_cal();
  r.display();
 }
}
OUTPUT
C:\>javac StudentDetails.java
C:\>java StudentDetails
Student Name : Aashish
Roll no : 11
Marks1 : 75
Marks2 : 95
Percentage = 85.0

Comments

  1. Replies
    1. The effectiveness of IEEE Project Domains depends very much on the situation in which they are applied. In order to further improve IEEE Final Year Project Domains practices we need to explicitly describe and utilise our knowledge about software domains of software engineering Final Year Project Domains for CSE technologies. This paper suggests a modelling formalism for supporting systematic reuse of software engineering technologies during planning of software projects and improvement programmes in Project Centers in Chennai for CSE.

      Software management seeks for decision support to identify technologies like JavaScript that meet best the goals and characteristics of a software project or improvement programme. JavaScript Training in Chennai Accessible experiences and repositories that effectively guide that technology selection are still lacking.

      Aim of technology domain analysis is to describe the class of context situations (e.g., kinds of JavaScript software projects) in which a software engineering technology JavaScript Training in Chennai can be applied successfully

      Delete
  2. Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article.
    Dissertation Examples

    ReplyDelete
  3. very interesting article and informative one. i can learn more about java. best java training in chennai

    ReplyDelete
  4. If you want to learn advance Java programming so connect with BR Brains Java training institute in Jaipur, which provide best advance java training course.

    ReplyDelete
  5. a large number of the present understudies getting through the lawyer's exam are experiencing issues following the call of a paper question; they are not recognizing an UNIVERSITY IN KENYA
    adequate number of issues in the reality designs; they are experiencing difficulty applying the law to the certainties and breaking down them; and their punctuation and spelling isn't satisfactory.

    ReplyDelete
  6. Today, most clients have able customer machines which can do considerably more than HTML permits. what is programming language

    ReplyDelete
  7. Having Insufficient Material: Nothing aggravates a book advertiser more than endeavoring to advance a book that isn't promotable. What makes a book unfit to be advanced? amryl

    ReplyDelete
  8. high-quality web site, where did u come happening taking into consideration the mention coarsely this posting?i've addiction in a number of the articles almost about the order of your website now, and i in reality in imitation of your fashion. thanks 1,000,000 and engross keep going on the functioning discharge loyalty. BA 2nd Year Results

    ReplyDelete
  9. In your blog I was happy to see your article, better than last time, and have made great progress, good samaritan school jasola I am very pleased. I am looking forward to your article will become better and better.

    ReplyDelete
  10. Native apps do not need internet connectivity to function this gives users anytime, anywhere access.
    mobile app development london

    ReplyDelete
  11. Very efficiently written information. BCom 1st Year Result It will be beneficial to anybody who utilizes it, including me. Keep up the good work. BCom 2nd Year Result For sure i will check out more posts. This site seems to get a good amount of visitors.BCom 3rd Year Result

    ReplyDelete
  12. Thank you for this! this is very helpful. I'm impressed with your blo...

    BA 2 YEAR REVALUATION RESULT

    ReplyDelete
  13. This is a great post. BA 1st Year Result I like this topic.This site has lots of advantage. BA 2nd Year Result I found many interesting things from this site. It helps me in many ways.Thanks for posting
    this again. BA 3rd Year Result

    ReplyDelete
  14. This is a great inspiring article.I am pretty much pleased with your work.You can really really helpful information. Keep it up. Keep blogging. Looking to your next post.
    best dissertation writing service

    ReplyDelete
  15. There are lots of dissertation internet websites on-line since you attain web famous from the site. web services testing

    ReplyDelete
  16. Write a program to display student CMS, marks in three subjects and total marks. Consider class student stores the roll no, class test, stores marks of three subjects class result contains total marks obtained in test. The class result can inherit the details of the
    mark obtained in test and roll no of a student through multilevel inheritance.

    ReplyDelete
  17. Your post is very great.i read this post this is a very helpful. i will definitely go ahead and take advantage of this. You absolutely have wonderful stories.Cheers for sharing with us your blog. python training in noida

    ReplyDelete
  18. Great articles and great layout. Your blog post deserves all of the positive feedback it’s been getting. 50 free instagram likes instantly

    ReplyDelete
  19. I am definitely enjoying your website. You definitely have some great insight and great stories.
    Write My Assignments For Me

    ReplyDelete
  20. A very delightful article that you have shared here. Your blog is a valuable and engaging article for us, and also I will share it with my companions who need this info. Thankful to you for sharing an article like this.Aws Training in Delhi

    ReplyDelete
  21. Your post is really good thanks for sharing these kind of post but if anyone looking for Best Consulting Firm for Fake Experience Certificate Providers in hyderabad, India with Complete Documents So Dreamsoft Consultancy is the Best Place.Further Details Here- 9599119376 or VisitWebsite-https://experiencecertificates.com/experience-certificate-provider-in-Hyderabad.html

    ReplyDelete
  22. I really liked while reading your article, the information you have mentioned in this post is really good. I am waiting for your upcoming post your ,post is really good . Otherwise if anyone want to Learn javaCourse So Contact Us-9311002620 Or check my website- https://www.htsindia.com/Courses/tally/tally-training-course

    ReplyDelete
  23. This comment has been removed by the author.

    ReplyDelete
  24. Have to work? need of money but have no experience certificate. Get in touch with us we provide experience certificate in Gurgaon 100% genuine certificate in Gurgaon. It will help it your courier. So don’t be late. Get your experience letter now. For experience letter in Delhi contact at 9599119376 or can visit our website at https://experiencecertificates.com/experience-certificate-provider-in-Gurgaon.html


    ReplyDelete
  25. Nice Blog, it is very Impressive. keep sharing good information with us.

    Learn Java Online
    JAVA Course in Chennai
    Java Course in Bangalore

    ReplyDelete

Post a Comment

Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Program to input age from user and throw user-defined exception if entered age is negative

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.