can someone explain me why i cant compile this
class k{
String[][] first = new String[1][3];
first[0][0]= "p";
}
Printable View
can someone explain me why i cant compile this
class k{
String[][] first = new String[1][3];
first[0][0]= "p";
}
You did not define a main() in your class.
it should be
All Programs need a starting position. In Java The Main() method is that starting position. Once I added that into your program I was able to compile and run the code.Code:class k
{
public static void main(String[] myArgs)
{
String[][] first = new String[1][3];
first[0][0]= "p";
{
}
Your explanation is not related to compilation.Quote:
Originally Posted by javatier
The first line is okay since it is a declaration statement, so the compiler will not complain about it. However, the second line is an assignment and it needs to be declared in some method or a static code block, failing which you get a compilation error.Quote:
Originally Posted by eruditionist
This is the actual code
class j
{
String[][] first = new String[1][3];
first[0][0]= "p";
void method(){
System.out.println(first[0][0]);
}
}
class k{
public static void main(String[] args){
j one = new j();
System.out.println(one.method());
}
}
and it says identifier expected.
A method must have an identifier...public, private, protected