java - Store the main class values in subclass as an Array -


please me add array in student class. input values in main class needs stored in student class , can displayed calling method showdata().

import java.util.scanner; 

public class library {

public static void main(string[] args) {     student record = new student();     int roll;     string name;     int mob;     int i;      scanner sc = new scanner(system.in);      system.out.println("enter roll numer of student \n");     roll = sc.nextint();     system.out.println("enter name of student \n");     name = sc.next();     system.out.println("enter mobile number of student \n");     mob = sc.nextint();      record.getdata(roll, name, mob);  record.showdata(); } } 

this subclass student

public class student {

int roll; string name; int mob; int = 0;  void getdata(int roll, string name, int mob) {      this.roll = roll;     this.name = name;     this.mob = mob;  }  void showdata() {      //for(i=0; < 3; i++)      system.out.println("roll number " + roll + "\nname " +  name + "\nmobile number " + mob); } } 

you have inherit subclass main class.. inheritance process enables 1 class acquire properties(methods , variable) of another.. class inheriting properties of called subclass (also called derived class).where class properties inherited super class (base class or parent class) example:

class ajay extends jay{ // } 

here

  • ajay main class..

  • jay sub class..

for code:

import java.util.scanner; public class library extends student{ public static void main(string[] args) {     student record = new student();     int roll;     string name;     int mob;     int i;      scanner sc = new scanner(system.in);      system.out.println("enter roll numer of student \n");     roll = sc.nextint();     system.out.println("enter name of student \n");     name = sc.next();     system.out.println("enter mobile number of student \n");     mob = sc.nextint();      record.getdata(roll, name, mob);  record.showdata(); } } public class student {  int roll; string name; int mob; int = 0;  void getdata(int roll, string name, int mob) {      this.roll = roll;     this.name = name;     this.mob = mob;  }  void showdata() {      //for(i=0; < 3; i++) system.out.println("roll number " + roll + "\nname " +  name + "\nmobile number " + mob); } } 

please check now..and vote me back.!


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -