class Test { protected int x, y;} class Main { public static void main(String args[]) { Test t = new Test(); System.out.println(t.x + " " + t.y); }}0 0Run Time ErrorCompiler ErrorNone of the above
Question
class Test { protected int x, y;} class Main { public static void main(String args[]) { Test t = new Test(); System.out.println(t.x + " " + t.y); }}0 0Run Time ErrorCompiler ErrorNone of the above
Solution
The code will output "0 0".
Explanation: In Java, when you create an object of a class (in this case, the class is "Test"), the instance variables (x and y) are automatically initialized to their default values. For integer data types, the default value is 0. So, when you print the values of x and y, it will print "0 0".
Similar Questions
class Test { public static void main(String[] args) { for(int i = 0; 1; i++) { System.out.println("Hello"); break; } }}Compiler ErrorRun Time ErrorHello Hello HelloHello
public class Test { public void m1(String arg1) { arg1="Test"; } public static void main(String[] args) { Test test1= new Test(); String s= "Hello"; test1.m1(s); System.out.println(s); }}
Analyze the following code carefully.public class Test { int x; public Test(String t) { System.out.println("Test"); } public static void main(String[] args) { Test test = new Test(); System.out.println(test.x); }}Group of answer choicesThe program has a compile error because you cannot create an object from the class that defines the object.The program has a compile error because x has not been initialized.The program has a compile error because System.out.println method cannot be invoked from the constructor.The program has a compile error because Test does not have a default construc
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
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
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.