Hey, Hi all!
I'm a bachelor student, new to Java.
Following code is giving error in PrintDetails()
What parameters should I define in it??
Kindly check and tag out my mistakes in the following code.. Thanks ^_
^

class student
{
String a;String b;char c;double d;
student(String name,String rollno,char gender,double gpa)
{
a= name; 
b= rollno;
c= gender; 
d= gpa;
}
}

class teacher
{
String e;String f;long g;String h;
teacher(String name,String address,long telephoneno,String degree)
{
e=name;
f=address;
g=telephoneno;
h=degree;
}
}

class course
{
student s1;
student s2;
teacher t1;
int age;
course(student x,student y,teacher z)
{
s1=x;
s2=y;
t1=z;
}

void printDetails()
{
System.out.println();
}
}

public class test1
{
public static void main(String args[])
{
student name=new student();
course c1=new course("aaaa","11cs11",'f',6.8);
course c2=new course("uuu","8u8",'p',7.9);
course c3=new course("uuuttt","99oi88",'m',9.7);
course j[]={c1,c2,c3};
c1. printDetails();
c2.printDetails();
c3.printDetails();
}
}

Dani AI

Generated

The compile problem is not System.out.println itself — it’s that main is calling the wrong constructor. Your course constructor expects two student objects and a teacher, but main is trying to pass name/roll/gender/gpa directly into new course(...). Build the student and teacher objects first, then pass them into course. printDetails() can take no parameters and simply print the instance fields (s1, s2, t1).

A minimal corrected approach (keeps the same data model but fixes construction and printing):

class Student {
    String name, roll;
    char gender;
    double gpa;
    Student(String name, String roll, char gender, double gpa) {
        this.name = name; this.roll = roll; this.gender = gender; this.gpa = gpa;
    }
    public String toString() { return name + " (" + roll + ") gpa:" + gpa; }
}

class Teacher {
    String name, address, degree;
    long phone;
    Teacher(String name, String address, long phone, String degree) {
        this.name = name; this.address = address; this.phone = phone; this.degree = degree;
    }
}

class Course {
    Student s1, s2; Teacher t;
    Course(Student s1, Student s2, Teacher t) { this.s1 = s1; this.s2 = s2; this.t = t; }
    void printDetails() {
        System.out.println("Students:");
        System.out.println("  " + s1);
        System.out.println("  " + s2);
        System.out.println("Teacher: " + t.name + " phone:" + t.phone);
    }
}

In main, create Student and Teacher first, then new Course(s1, s2, t). Use a trailing L for long literals (e.g., 1234567890L). As asked, post the exact compiler error if this still fails. ’s comment about printing is correct in spirit — an empty println only prints a blank line — but your immediate issue is the constructor/type mismatch. For cleaner code later, follow Java naming conventions (capitalize class names), make fields private, and add getters or override toString() as shown.

Recommended Answers

All 4 Replies

code is giving error
Please post the full text of the error message.

Please edit your code and add proper indentations to the code of 3-4 spaces at each level of logic nesting. There shoudl not be 2 } in line veritically.

System.out.println();

you'll need to provide a String as parameter to be printed
System.out.println("this will be printed");
for instance

System.out.println();

commented: A useless post -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.