Over a million developers have joined DZone.

Java Quiz: Using Inheritance and Static Methods

A new quiz for advanced Java programmers on the behavior of Java inheritance and static methods.

· Java Zone

Learn more about how the Java language, tools and frameworks have been the foundation of countless enterprise systems, brought to you in partnership with Salesforce.

Last Week's Answer

ClassA classA = new ClassA(new ClassB(new ClassB().method(2)));

  new ClassB().method(2)
  System.out.print(new ClassA().method()); //the method returns y=0
  System.out.print(new ClassB(4).method(3)); //the method returns x+i=3+3=6
System.out.print(i); i=4 ;
   new ClassB(new ClassB().method(2));
   new ClassB().method(2) returns x+i = 3+2=5
   new ClassB(new ClassB().method(2)) = new ClassB(5);
   System.out.print(i); i=5
   new ClassA(new ClassB(new ClassB().method(2))) = new ClassA(new ClassB);
     classB.method(1); returns x + i = 3+1 = 4

The result is 46054.

This Week's Quiz 


  1. Introduce some tricks and behaviors of Java inheritance and overwriting methods.

  2. Compare an instance variable with a static variable.

  3. Mind training for programmers to improve their imaginations and expectations. 

What is written to the standard output as the result of executing the following code?

public class MySuper {

    int x = 2;
    static int s = 3;

    MySuper() {
        x += 4;
    MySuper(int x) {
        x += x + 20;
    public MySuper method(){
        x += 35;
        return new MyClass();

public class MyClass extends MySuper {

    public MyClass() {
        x -= 7;
        s += x;
    public MySuper method(){
        x += 7;
        return super.method();
    public static void main(String[] args){
        MyClass mc = new MyClass();

Let us know if you have any questions or comments on our quiz series, and as always, you can find Sar here

Discover how the Force.com Web Services Connector (WSC) is a code-generation tool and runtime library for use with Force.com Web services, brought to you in partnership with Salesforce.

java,quiz,inheritance,static methods

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}