Code:
import java.util.Scanner;
class Student
{
// Instance Variable
int rollno,m1,m2,m3;
String name;
void getdata()
{
Scanner scan = new Scanner(System.in);
System.out.println("\n\n Enter Student Name , roll no , and marks of 3 subject: ");
name = scan.nextLine();
rollno = scan.nextInt();
m1 = scan.nextInt();
m2 = scan.nextInt();
m3 = scan.nextInt();
}
}
class Result extends Student
{
int total ;
float average;
void cal()
{
total = m1+m2+m3;
average = total / 3.0f;
System.out.println(" Total marks: "+total);
System.out.println(" Average: "+average);
}
public static void main( String args[] )
{
Result r = new Result();
r.getdata();
System.out.println("\n\n Student Details: \n");
System.out.println("Name: "+r.name);
r.cal();
}
}
Ouput:
import java.util.Scanner;
class Student
{
// Instance Variable
int rollno,m1,m2,m3;
String name;
void getdata()
{
Scanner scan = new Scanner(System.in);
System.out.println("\n\n Enter Student Name , roll no , and marks of 3 subject: ");
name = scan.nextLine();
rollno = scan.nextInt();
m1 = scan.nextInt();
m2 = scan.nextInt();
m3 = scan.nextInt();
}
}
class Result extends Student
{
int total ;
float average;
void cal()
{
total = m1+m2+m3;
average = total / 3.0f;
System.out.println(" Total marks: "+total);
System.out.println(" Average: "+average);
}
public static void main( String args[] )
{
Result r = new Result();
r.getdata();
System.out.println("\n\n Student Details: \n");
System.out.println("Name: "+r.name);
r.cal();
}
}
Ouput: