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 keyword
:
Content language: English
Русский
Given the following code: public class Foo { private Foo() { return this; // 1 } public static Foo get() { return new Foo(); // 2 } public static void main(String[] args) { Foo foo1 = get(); // 3 Foo foo2 = new Foo(); // 4 } } Will there be a compilation error and if so, in what lines?
static keyword
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 keyword
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 keyword
What will be the result of the following program compilation and execution? public class Test { private static class Test2 { private static final String name = "Name"; } public static void main(String[] args) { System.out.println(Test2.name); } }
static keyword
What will be the result of the following code execution? class A { private int counter = 0; public static int getInstanceCount() { return counter; } public A() { counter++; } } public class B { public static void main(String ar[]) { A a1 = new A(); A a2 = new A(); A a3 = new A(); System.out.println(A.getInstanceCount()); //1 } }
static keyword
What is the result of the following code compilation and execution? class A { private static void test1() { System.out.println("A.test1"); } static void test2() { test1(); } } public class B extends A { void test1() { System.out.println("B.test1"); } static void test2() { super.test2(); } public static void main(String[] args) { A a = new B(); a.test2(); } }
static keyword
What will be printed out as a result of the following code execution? public class Main { private static class A1 { private String test() { return "A1"; } } public static class A2 extends A1 { public String test() { return "A2"; } } public static class A3 extends A2 { public String test() { return "A3"; } } public static void main(String ... arg) { A1 a1 = new A1(); System.out.println(a1.test()); a1 = new A2(); System.out.println(a1.test()); a1 = new A3(); System.out.println(a1.test()); } }
static keyword
What will happen if you attempt to compile and run this code: class Mountain { static String name = "Himalaya"; static Mountain getMountain() { System.out.println("Getting Name "); return null; } public static void main(String[ ] args) { System.out.println( getMountain().name ); } }
static keyword
In which lines the parameter T is not allowed to use (select 3 choices): public class Test & lt; T & gt; { private T item; // (1) private static T [] storage = new T [100]; // (2) public Test (T item) {this.item = item; } // (3) public T getItem () {return item; } // (4) public void setItem (T newItem) {item = newItem; } // (5) public static void getAllItems (T newItem) {// (6) T temp; // (7) } } </ code> </ pre>
static keyword
What will be the output of the following code? class Super { static String ID = "QBANK"; } class Sub extends Super{ static { System.out.print("In Sub"); } } class Test{ public static void main(String[] args) { System.out.println(Sub.ID); } }
static keyword
← Prev
2
3
4
5
6
Next →
Sign Up Now
or
Subscribe for future quizzes