Skip to main content

Java inheritance question ?

package com.vit;

public class InheritanceDemo {

    public static void main(String args[])
    {
 
        Super1 super1 = new Super2();
        super1.base1();
       
        Super2 super2 = new Super3();
        super2.base1();
       
    }
}

class Super1
{
     public Super1()
     {
         System.out.println("with in super1()");
     }
     public void base1()
     {
         System.out.println("Base is called from super1");
     }
}


class Super2 extends Super1
{
     public Super2()
     {
         System.out.println("with in super2()");
     }
     public void base2()
     {
         System.out.println("Base is called from super2");
     }
   
}


class Super3 extends Super2
{
     public Super3()
     {
         System.out.println("with in super3()");
     }

     public void base1()
     {
         System.out.println("Base is called from super3");
     }
}





































---------Answer
with in super1()
with in super2()
Base is called from super2
with in super1()
with in super2()
with in super3()
Base is called from super3

Comments

Popular posts from this blog

ifference between @RestController and @Controller

Difference between @RestController and @Controller Annotation in Spring MVC and REST Read more:  http://javarevisited.blogspot.com/2017/08/difference-between-restcontroller-and-controller-annotations-spring-mvc-rest.html#ixzz4sbGy2Glh The  @RestController  annotation in Spring MVC is nothing but a combination of  @Controller  and  @ResponseBody  annotation. It was added into Spring 4.0 to make the development of RESTful Web Services in Spring framework easier. If you are familiar with the  REST web services  you know that the fundamental difference between a web application and a REST API is that the response from a web application is generally view (HTML + CSS + JavaScript) while REST API just return data in form of JSON or XML. This difference is also obvious in the  @Controller  and  @RestController  annotation. The job of  @Controller  is to create a Map of model object and find a view but  @RestContr...

Presentation topics

Topics for presentation : Knockout.js, Angular.js, Node,js, Kendo UI, MVC 4, Nuget, Ninject, Unity Framework, Dependency Injection , PMC Package Manager Control, Mordenizer, Moq, Json, Html5, Entity Framework code1st. Spring.net Castle Windsor , Structure Map and Microsoft Unity ,
What happens when you compile/run the following code: class MyClass { public static void main(String[] args) { new MyClass(); } Ans: It executes and create a object for that class without reference. The output of the program is nothing.