| | |
Calling methods and constructors from main method
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 4
Reputation:
Solved Threads: 0
Here is my Main method - calling Display. I am getting an error message, I don't know what I am missing. Any suggestions?
public class Student
{
private int studentID;
private double studentGPA;
public Student()
{
studentID=100;
studentGPA=3.0;
}
public Student(int id, double gpa)
{
studentID=id;
studentGPA=gpa;
}
public void AssignValues(int id, double gpa)
{
studentID=999;
studentGPA=3.75;
}
public void Display(int id, double gpa)
{
System.out.println("Student ID:"+" "+studentID);
System.out.println("Student GPA:"+" "+studentGPA);
}
}
public class DisplayStudent
{
public static void main(String[] args)
{
Student IDNGPA = new Student();
IDNGPA.Display();
}
}
Error message: DisplayStudent.java:11: Display(int,double) in Student cannot be applied to ()
IDNGPA.Display();
^
public class Student
{
private int studentID;
private double studentGPA;
public Student()
{
studentID=100;
studentGPA=3.0;
}
public Student(int id, double gpa)
{
studentID=id;
studentGPA=gpa;
}
public void AssignValues(int id, double gpa)
{
studentID=999;
studentGPA=3.75;
}
public void Display(int id, double gpa)
{
System.out.println("Student ID:"+" "+studentID);
System.out.println("Student GPA:"+" "+studentGPA);
}
}
public class DisplayStudent
{
public static void main(String[] args)
{
Student IDNGPA = new Student();
IDNGPA.Display();
}
}
Error message: DisplayStudent.java:11: Display(int,double) in Student cannot be applied to ()
IDNGPA.Display();
^
1
#2 Oct 17th, 2009
You are calling the ethod without any arguments, but the method is designed to take an int and a double, so give it an int and a double.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- Calling methods and constructors from a Main method (Java)
- Calling a variable from Main method to a new method. (Java)
- COnfused on calling methods (Java)
- a homework on methods, constructors etc (Java)
- Declaring and identifying methods (Java)
- how to pass non-static variable to main method (Java)
- How to invoke array varibles to another main method (Java)
- calling methods. (Java)
Other Threads in the Java Forum
- Previous Thread: Calling methods and constructors from a Main method
- Next Thread: Converting Image to greyscale
| Thread Tools | Search this Thread |
2dgraphics android api apple applet application arguments array arrays automation banking binary binarytree bluetooth capture chat chatprogramusingobjects class classes client code color component count database derby design eclipse eclipsedevelopment encryption error event exception fractal game givemetehcodez graphics gridlayout gui html ide if_statement image input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel julia keyword linux list loop macintosh map method methods midlethttpconnection mobile netbeans newbie object os print printing problem producer program programming project projectideas read recursion reference replaysolutions ria scanner screen server set size sms sort sourcelabs sql stop string swing threads transforms tree ui unicode validation windows






