一个JAVA练习题,我是小白,刚刚接触JAVA,求指导

2024-11-16 09:23:51
推荐回答(5个)
回答(1):

class student{
public String name;
public int age;
public int No;
public void sayMyName(){
System.out.println("我的名字叫:"+name);
}
public void study(){
System.out.println("我正在学习java");
}
}

回答(2):

public class Student{
 public String name;
 public int age;
 public String no;
 
 public void sayMyName() {
  System.out.println("我会叫:" + name);
 }

 public void study() {
  System.out.println("我正在学习JAVA");
 }
}

希望能帮到你

回答(3):

public class Student {
public String name;
public Integer age;
public String no;
  
public void sayMyName(){
System.out.println("我会叫"+name);
}
public void study(){
System.out.println("我正在学习java");
}
  
public static void main(String[] args){
Student s = new Student();
s.name = "张三";
s.sayMyName();
s.study();
}
}
结果
我会叫张三
我正在学习java

回答(4):

public class Student {

public String name;

public int age;

public int NO;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public int getNO() {
return NO;
}

public void setNO(int nO) {
NO = nO;
}

public void sayMyName(){
System.out.println("我会叫" + name);
}
public void study(){
System.out.println("我正在学习JAVA");
}
}

使用的是默认包
PS:我也是刚学习

回答(5):

public class Student {

public String name;
public int age;
public int no;

public Student(String name, int age, int no){
this.name = name;
this.age = age;
this.no = no;
}

public void sayMyName(){
System.out.println("我会叫" + name);
}

public void study(){
System.out.println("我正在学习JAVA");
}

public static void main(String[] args) {
Student student = new Student("小明", 18, 1001);
student.sayMyName();
student.study();
}
}