Multiple inheritance Program Code in Java

The code Below implements the concept of multiple inheritance.The program takes Roll number of student as input using one class. Then Marks obtained in two subject .Later the marks are added together along with bonus marks and total is printed.The code is implemented using multiple inheritance concept in mind.
You can use JDK or Netbeans IDE to run below code.

                                                                     
CODE:                                                                     
                                                                     
                                             
package mulinheritance;
import java.io.*;
	class student
	{
      	int rn;
  	void getNumber(int n)
  	{
      	rn = n;
 	 }
  	void putNumber()
  	{
   	   System.out.println("Roll Number: " +rn);
  	}
	}

	class test extends student
	{
    	float pt1, pt2;
 	void getMarks(float m1, float m2)
 	{
     	pt1 = m1;
     	pt2 = m2;
	 }
 	void putMarks()
 	{
     	System.out.println("<Marks Obtained>");
     	System.out.println("sports: " +pt1);
     	System.out.println("computer: " +pt2);
 	}
	}
 	interface theory
 	{
     	float theory= 10.0F;
     	void putWt();
	 }

	class result extends test implements theory
	{
    	float total;
    	public void putWt()
   	 {
      	 System.out.println("practical score: " +theory);
    	}
    	void display()
    	{
        total = pt1+pt2+theory;
        putNumber();
        putMarks();
        putWt();
        System.out.println("Total score: " +total);
       }
	}
	public class mulinheritance {
   	 public static void main(String[] args)throws Exception {
        try
        {
        result stud1 = new result();
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the roll number: ");
        int num = Integer.parseInt(bf.readLine());
        stud1.getNumber(num);
        System.out.println("Enter the marks in sports: ");
        int ma = Integer.parseInt(bf.readLine());
        System.out.println("Enter the marks in computer: ");
        int sc = Integer.parseInt(bf.readLine());
        stud1.getMarks(ma,sc);
        stud1.display();
        }
        catch(Exception e) { }
        
    }

}


OUTPUT:                                                            
                                             
	Enter the roll number: 
	23
	Enter the marks in sports: 
	56
	Enter the marks in computer: 
	67
	Roll Number: 23
	<Marks Obtained>
	sports: 56.0
	computer: 67.0
	practical score: 10.0
	Total score: 133.0




0 comments:

Post a Comment

If You Are Asking Some Question On This Comment Then Click On Subscribe by email Link