public class Student1{ int id; String name;
My first Java program
3
public class Student1{
int id;
String name;
Student1(int i,String n){
id=i;
name=n;}
public String getName(String n)
{return name;}
public static void main(String args[]){
Student1 s1=new Student1(3,"Sergiu");
System.out.println(s1.getName(""));
}
}
This is what came out after dozens of tries trying to learn about the syntax, constructors and getters. How would you do the program in a simpler way?
The goal is to define a Student object in main and to output one of its parameters.
PS: I'm ready to become a programmer, guys!
int id;
String name;
Student1(int i,String n){
id=i;
name=n;}
public String getName(String n)
{return name;}
public static void main(String args[]){
Student1 s1=new Student1(3,"Sergiu");
System.out.println(s1.getName(""));
}
}
This is what came out after dozens of tries trying to learn about the syntax, constructors and getters. How would you do the program in a simpler way?
The goal is to define a Student object in main and to output one of its parameters.
PS: I'm ready to become a programmer, guys!
- JMondaCom
- Jamesvictor
- minirich
Next Topics on Trending Feed
-
3