java - Why is the variable of object of class box not being overwritten in another class? -
public class box{ public int length,width,height; public int volume; box(int i, int j, int k){ this.length=i; this.width=j; this.height=k; } void setvolume(int i){ this.volume=i; } int getvolume(){ homecoming volume; } } class bigbox{ box b1=new box(20,30,40); b1.length=30; }
i created class box , class bigbox overwrites length variable of object of class box 30. when write code b1.length=30 overwrite it, shows error unable understand. can help me out?
you need set assignments within code block, method or maybe initializer block.
class bigbox{ public void somemethod() { box b1=new box(20,30,40); b1.length=30; } } if trying initialize instance variable, work:
class bigbox{ box b1=new box(20,30,40); { b1.length=30; } } java class overwrite
No comments:
Post a Comment