Kasturi R Kasturi R - 5 months ago 9
Java Question

This is a Java program I tried. But I could not find where I did wrong with the code

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package exams;

public class ExamDetails {

public static void main (String[] args){

StudentResults aStudent = new StudentResults();


String sName = aStudent.fullName("Bill Gates");
System.out.println(sName);

}

class StudentResults{

private String Full_Name;
private String Exam_Name;
private String Exam_Score;
private String Exam_Grade;

StudentResults(){
Full_Name = "No Name Given";
Exam_Name = "Unknown";
Exam_Score = "No Score";
Exam_Grade = "Unknown";
}

String fullName(String aName){

Full_Name = aName;
return Full_Name;

}

}

}

Answer

Make following changes :

public class ExamDetails {

    static  StudentResults aStudent = new StudentResults();
    public static void main (String[] args){




        String sName = aStudent.fullName("Bill Gates");
        System.out.println(sName);

    }

    static class StudentResults{

    private String Full_Name;
    private String Exam_Name;
    private String Exam_Score;
    private String Exam_Grade;

    StudentResults(){
        Full_Name = "No Name Given";
        Exam_Name = "Unknown";
        Exam_Score = "No Score";
        Exam_Grade = "Unknown";
    }

    String fullName(String aName){

        Full_Name = aName;
        return Full_Name;

    }

}

}

Or second option is to declare StudentResults in seperate file