Given a sample code:
public class SampleCode {
public static void main(String args[]){
SampleCode sc = new SampleCode();
sc.meth();
}
public void meth(){
int arr[] = new int[] {1,2,3,4};
System.out.print(arr.length);
}
}
What will happen when you compile and run the given code?
1) Compile and print 4
2) Cant access method outside class
3) Compile time error
4) Compile but give runtime error.
(1)
This program will compile and execute with 4 as output.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.