Quizzes
Site Language: English
Українська
English
Русский
Programming Tests
Login
Sign Up
Programming Tests
Theory
Snippets
Papers
Landing
Android
Prices
FAQ
Cosmo Story
Terms and Conditions
Privacy Policy
Cookies Policy
Send Feedback
static block
:
Content language: English
Русский
What happens when you try to compile / run the following code: abstract class Animal { static { System.out.println("Inside Animal"); } } class Cat extends Animal { static { System.out.println("Inside Cat"); } } class Dog extends Animal { static { System.out.println("Inside Dog"); } } public class Main { public static void main(String[] args){ Animal cat = new Cat(); Animal dog = new Dog(); } }
static block
What happens as a result of compiling and running the following code: public class Bar extends Foo { // 1 public static void main(String[] args) { // 2 System.out.print(sum(1, 2)); // 3 } } class Foo { int sum(int x, int y) { return x + y; } }
static block
What will be brought up in the console? public class Test { { System.out.println("1"); } Test () { System.out.println("2"); } static { System.out.println("3"); } { System.out.println("4"); } public static void main(String[] args) { new Test(); } }
static block
What is the result of compiling and running programs (JDK to version 6 inclusive) when starting the class considered MainClass? public class MainClass { static { MyClass m = new MyClass(); // 1 System.out.println(m.toString()); // 2 System.exit(0); } } class MyClass { public String toString() { return "MyClass"; } }
static block
What happens when you try to compile and run this code: public class QTest { { System.out.print("1"); } public static void main(String[] args) { System.out.print("2"); new QTest(); } static { System.out.print("3"); } }
static block
What will be printed as the result of the following code execution? public class GoodbyeWorld { public static void main(String[] args) { System.out.print(A.i); System.out.print(B.i); } } class A { static { i = 2; } static int i = 1; }; class B { static int i = 1; static { i = 2; } };
static block
What will be the result of the following code execution? class A { static String a; {print("a");} static {a = print("A");} A() {} static String print(String s) { System.out.print(s + " "); return s; } } class B extends A { static String b; {print("b");} static {b = print("B");} B() {} } class Test { public static void main(String... args) { System.out.print(B.a); } }
static block
← Prev
1
Next →
Sign Up Now
or
Subscribe for future quizzes