- 1
Right now I'm working on methods and classes. I wrote this code but couldn't run. It has some errors. Please check and advice. Thanks
public class humans{ int height ; int weight ; int ethincity; void walk(){ System.out.println("he walked like lion" ); } } class myclass{ public static void main(String[] args) { humans t1 = new humans(); humans t2 = new humans(); humans t3 = new humans(); humans t4 = new humans(); t1.height = "6"; t2.weight ="85"; t3.ethincity="indian"; System.out.printf(t1.height); System.out.printf(t2.weight); System.out.printf(t3.ethincity); t4.walk(); }}
3 Antworten
0
Firstly remove the quotation marks around the values that you've assigned to the objects attributes and also the t3.enthincity attribute expects an integer value but you've assigned it a string value.
- 1
you have some mistake
you define ethicty as int then you put a string on it
i think your variable should be public and some another problem
- 1
you are passed string value in integer variable
try this :-
t1.height=6;
t2.weight=85;
and you have to change the dataType of ethincity variable
from integer to string.