无法创建子类的动态实例

时间:2018-05-19 17:35:46

标签: java oop inheritance instance subclass

我正在创建一个使用继承的学生注册程序,其中我想创建由用户在提示总学生时输入的学生的动态实例,但我无法这样做。 任何帮助将不胜感激。

  

import java.util.*;

class Course{
    static Scanner input=new Scanner(System.in);
    String courseName;
    String preReq;
    static int totalStudents;

    Course(){
        System.out.println("Course Details:");
        System.out.print("Enter name of course: ");
        courseName=input.nextLine();
        System.out.print("Enter pre-requisite: ");
        preReq=input.nextLine();
        System.out.println("Class Details:");
        System.out.print("Enter no# of students: ");
        totalStudents=input.nextInt();
    }
}
class Student extends Course{
    String studentName;
    String studentCms;
    static int count=0;
    String confirm;

    Student(){
        count+=1;
        System.out.println("Student Details:");
        System.out.println("Enter name of student #"+count+": ");
        studentName=input.nextLine();
        System.out.println("Enter CMS id of student #"+count+": ");
        studentCms=input.nextLine();
        System.out.println("Enter Y/y to register in course: ");
        confirm=input.next();
    }
}

public class CourseRegistration{
    public static void main(String args[]){
        Student ob=new Student();
    }
}

0 个答案:

没有答案