Determine the outputpublic class Trial{public static void main(String[] args) { int arr[4]={}; System.out.print(arr[0]); }}Select one:a.Garbage errorb.Compile time errorc.Runtime errord.0
Question
Determine the outputpublic class Trial{public static void main(String[] args) { int arr[4]={}; System.out.print(arr[0]); }}Select one:a.Garbage errorb.Compile time errorc.Runtime errord.0
Solution
b. Compile time error
Explanation: In Java, you cannot specify the size of the array when you declare it. The correct way to declare and initialize an array in Java is as follows:
int[] arr = new int[4];
So, the given code will throw a compile-time error.
Similar Questions
Select the correct answerPredict the output of following Java program.?class CT { public static void main(String args[]) { int a; System.out.println(a); } } Optionscompiler errorgarbage value0runtime error
What will be the output of the following code snippet?public class MyClass { static int value = 10; public void printValue() { System.out.println(value); } public static void main(String[] args) { MyClass obj = new MyClass(); obj.printValue(); }}Question 4Answera.0b.10c.Compilation errord.Runtime exception
class Sample{ private double num = 100; private int square(int a){ return a*a; }} public class Test{ public static void main(String args[]){ Sample obj = new Sample(); System.out.println(obj.num); System.out.println(obj.square(10)); } }Select one:a.Compile time errorb.100c.Run time errord.Executes but no output
What is the output of the following code?public class Solution { public void display() { int x = 10; } public static void main(String args[]) { System.out.println(x); }}Options: Pick one correct answer from below100Compile time errorRuntime error
elect the correct answerPredict the output ?class Test { public static void main(String args[]) { int arr[] = new int[2]; System.out.println(arr[0]); System.out.println(arr[1]); }}OptionsCompiler Errorgarbage valuegarbage value00Exception
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.