car.java
package com.krishna;
public class car {
private int door;
private int wheels;
private String model;
private String engine;
private String colour;
public void setModel(String model)
{
String validModel=model.toLowerCase();
if(validModel=="krish"||validModel=="raju")
{
this.model = model;
}
else
{
this.model="unknown";
}
}
public static String getModel()
{
return this.model;
}
}
Main.java
package com.krishna;
public class Main {
public static void main(String[] args) {
// write your code here
car obj1=new car();
car obj2=new car();
obj1.setModel("krish");
System.out.println(obj1.getModel());
}
}
静态函数不能用java中的这个keword引用
答案 0 :(得分:1)
静态方法属于该类而不属于该类的对象。从static
中删除static String getModel()
关键字,以实现此目的。