---
# System prepended metadata

title: java compile time binding vs runtime binding

---

# java compile time binding vs runtime binding 

###### tags: java
```
class A {
  int temp = 10;
  public void print()
  {
    System.out.println("In Class A");
  }
}
class B extends A {
  int temp = 20;
  public void print()
  {
    System.out.println("In Class B");
  }
}
public class Test5 {
  public static void main(String args[])
  {
    A a = new B();
    System.out.println(a.temp);
    a.print();
  }
}
```

output:

```
10
In Class B

```

so basically the class fields are bound at compile time, but the method will be bound at runtime, seems weird so noting it down.