class - Java riddle: static binding -


i'm given class c , interface a , i'm not allowed changes in them. should write class b code output success!

there 2 things don't understand in code of class c inside loop.

1) don't understand bar method called.

2) when return reached return to?

should change implementation of b in order work?

public interface {      public string bar(); }    public class c extends b {      public int foo = 100;      public c(string s) {         super(s);     }      @override     public void barbar() {         foo++;     }      public static void main(string[] args) {         string input = args[0];         stringbuilder builder = new stringbuilder(input);         c c = new c(input); //c=args[0]         b b = c; //b=args[0]         a = b; //a=args[0]          (int = 0; < args.length; i++) {             if (!builder.tostring().equals(a.bar())) { //which bar called?                 return; //where return to? exist loop?             }             builder.append(input);             c.foo++;         }          if (c.foo - 99 == b.foo.length() / input.length()) {             system.out.println("success!");         }     } }   public class b implements {        public string foo;      public b(string s) {         this.foo=s;     }      public void barbar() {         // todo auto-generated method stub      }      @override     public string bar() {         return this.foo;     }  } 

  1. bar() defined in class b called ofcourse. if believe method interface a called, must tell methods interface never called. interfaces have method declarations(unless it's default method) implementing non-abstract class has define. , line return this.foo executed.

  2. return statement main method ends program. returns jvm, in turn returns os.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -