So, I recently started class and objects in java and was solving the question: Create a class named 'Student' with String variable 'name' and integer variable 'roll_no'. Assign the value of roll_no as '2' and that of name as "John" by creating an object of the class Student.
This is the code I wrote:
public class Student {
String name;
int roll_no;
}
I saved this in one file and
import java.util.Scanner;
public class Studentdemo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Student s = new Student();
System.out.print("Enter the name: ");
s.name = sc.next();
System.out.print("Enter the roll number: ");
s.roll_no = sc.nextInt();
System.out.println("Name = " + s.name + "\nRoll No. = " + s.roll_no);
}
}
I saved this in another file and tried to compile and run this code
error: cannot find symbol
Student s = new Student();
^
symbol: class Student
location: class Studendemo
ef.java:9: error: cannot find symbol
Student s = new Student();
^
symbol: class Student
location: class Studendemo
2 errors
error: compilation failed
I tried to run this code in an online compiler, it was running fine on that but not on ubunt