با سلام خدمت دوستان عزیز.
من تازه کار هستم .
با خطای زیر روبرو شدم.
non-static variable this cannot be referenced from a static contextاینم از کدی که در حال نوشتن اون بودم. به نظرتون مشکل کار من از کجاست؟
package firstjavaprogram;
import firstjavaprogram.Firstjavaprogram.Box;
/**
*
* @author Ghs
*/
public class Firstjavaprogram {
public class Box
{
double width;
double height;
// structors Section
Box(double width , double height)
{
this.width=width;
this.height=height;
}
Box()
{
this.width=5;
this.height=2;
}
// methods Section
public double mohiteMostatil ()
{
return width*height;
}
public double masahat ()
{
return width*4;
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
در این خط خطا رخ میدهد Box myBox = new Box(5,2);
System.out.print(myBox.masahat());
}
}