Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //order of execution when we extends a class ....
- //base class is super class
- //child class is called subclass...
- //order of execution of main method is from the sub class...if their is no main method in sub class then their
- //is the execution of main method of the super class execute.
- //if their is main method in sub class then no main method of super class will execute.
- class A1{
- static int a = m1();
- static int m1(){
- System.out.println("a::" + a);
- System.out.println("Static m1() method");
- return 10;
- }
- static{
- System.out.println("Static Block");
- }
- public static void main(String args[]){
- System.out.println("A1 main() method");
- }
- }
- class B1 extends A1{
- static int b=m2();
- static int m2(){
- System.out.println("Class B1 and method is m2()");
- return 15;
- }
- static {
- System.out.println("Static Block of B1 class i.e Sub Class");
- }
- public static void main(String args[]){
- System.out.println("B1 main() method");
- System.out.println("A::" + a);
- System.out.println("B::" + b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment