English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories
1

this program not work in java

error is w and h not foun

so correct it
+++++++++++++++
class box{
int w=0;
int h=0;
}

class exam {
public static void main (String args[]) {
int x;
box first = new box();

first.w=10;
first.h=20;
x=w*h;

System.out.println("x"+x);

}
}

2007-08-04 01:59:47 · 4 answers · asked by robin j 1 in Computers & Internet Programming & Design

4 answers

Two things:

1. you need to make the two members w and h of the class box public : public int w=0; public int h=0;
2. in the second last code line you write x = w*h, while it should read x=first.w * first.h;

2007-08-04 02:03:37 · answer #1 · answered by Martin I 3 · 1 0

class box{
int w=0;
int h=0;
}

class exam {
public static void main (String args[]) {
int x;
box first = new box();

first.w=10;
first.h=20;
x=w*h;

System.out.println(x);

}
}

2007-08-04 15:39:29 · answer #2 · answered by selvakumar n 1 · 0 0

w & h are private members of class & you cant access them directly. Use public keyword before their declaration instead.

2007-08-05 07:21:59 · answer #3 · answered by Reverse Swing 3 · 0 0

not me would love to but no idea

2007-08-04 09:06:40 · answer #4 · answered by Michael M 7 · 0 0

fedest.com, questions and answers