0% found this document useful (0 votes)
3 views

VSB3

The document provides a Java program that demonstrates multiple inheritance through interfaces to calculate and display a student's marks. It includes classes for student details, test scores, and an interface for sports weight, culminating in a result class that computes the total score. The program prompts the user for input and displays the student's information and scores in a formatted output.

Uploaded by

varshavhegde11
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

VSB3

The document provides a Java program that demonstrates multiple inheritance through interfaces to calculate and display a student's marks. It includes classes for student details, test scores, and an interface for sports weight, culminating in a result class that computes the total score. The program prompts the user for input and displays the student's information and scores in a formatted output.

Uploaded by

varshavhegde11
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

NAME: VARSHA V HEGDE CLASS: 1 BCA-D ROLL NO:CA24244

3. Write a program to calculate marks of a student using multiple inheritance implemented


through interface.

 Class student with data members roll number, class, name and methods set and put
data.
 Create another class test extended by student with data members mark 1, mark 2, mark
3 and methods set and put data.
 Create interface sports with members sports weight=5 and put weight method.
 Now let the class result extends class test and implements interface sports.
 Write a java program to read required data and display details in neat format.

import java.util.*;

class student

int rollNo;

String name;

String cls;

void getData(int n,String nm,String c)

rollNo=n;

name=nm;

cls=c;

void putData()

System.out.println("Roll number="+rollNo);

System.out.println("Name:"+name);

System.out.println("class:"+cls);

ALVA’S COLLEGE MOODBIDRI PAGE NO:


NAME: VARSHA V HEGDE CLASS: 1 BCA-D ROLL NO:CA24244

class test extends student

int mark1,mark2,mark3;

void getMarks(int m1,int m2,int m3)

mark1=m1;

mark2=m2;

mark3=m3;

void putMarks()

System.out.println("Marks obtained");

System.out.println("Subject 1="+mark1);

System.out.println("Subject 2="+mark2);

System.out.println("Subject 3="+mark3);

interface sports

int sportswt=5;

public void putwt();

class result extends test implements sports

ALVA’S COLLEGE MOODBIDRI PAGE NO:


NAME: VARSHA V HEGDE CLASS: 1 BCA-D ROLL NO:CA24244

int total;

public void putwt()

total=mark1+mark2+mark3+sportswt;

System.out.println("Total Score="+total);

class partb3

public static void main(String args[])

Scanner s=new Scanner(System.in);

System.out.println("Enter the roll number");

int rollno=s.nextInt();

System.out.println("Enter the name of student");

String stname=s.next();

System.out.println("Enter the class of student");

String stclass=s.next();

System.out.println("Enter marks in 3 subjects");

int m1=s.nextInt();

int m2=s.nextInt();

int m3=s.nextInt();

result obj=new result();

ALVA’S COLLEGE MOODBIDRI PAGE NO:


NAME: VARSHA V HEGDE CLASS: 1 BCA-D ROLL NO:CA24244

obj.getData(rollno,stname,stclass);

obj.putData();

obj.getMarks(m1,m2,m3);

obj.putMarks();

obj.putwt();

OUTPUT:

ALVA’S COLLEGE MOODBIDRI PAGE NO:

You might also like