Skip to main content

What will be the Output?

class Parent
{
   static void show()
{
System.out.println("static show in Parent");
}
   void show1()
{
System.out.println("Parent show1");
}
}

class Child extends Parent
{
   static void show()
{
System.out.println("static show in Child");
}
   void show1()
{
System.out.println("Child show1");
}
   public static void main(String rk[])
{
Parent p = new Child();
p.show();
p.show1();
}
}

Predict the output and draw a conclusion from that regarding the invocation of static and non-static methods.

Comments

  1. output:static show in Parent
    Child show1
    conclusion:static method show() in child class is overriden by the show() method in parent class:while non static method show1() in child class can't be overriden by the
    method show1() in parent class:::::: it conclude that only static method can be overriden and not the non-static methods or members.

    ReplyDelete
    Replies
    1. Output will be a compile time error
      ..show method being overrided ...and its a static method ...abd static method can not be override.....

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Good Post! Thank you so much for sharing the post, it was so good to read and useful to improve
    Java Training in Electronic City

    ReplyDelete
  4. Good Post! Thank you so much for sharing the nice post, it was so good to read and useful to improve
    Java Training in Electronic City

    ReplyDelete

Post a Comment

Popular posts from this blog

ETE Practice Set-1

                                                                 Mock Test-1 -----------------------------------------------------------------------------------------------------------------------------   1 (a) Write a program that reads 10 integers between 1 and 100 and counts the occurrences of each. Assume the input ends with 0.                                                         ...

Practice Set: Unit-4

                                                                                                                Practice Set: Unit 4 1. What are the uses of super keyword in Java? Explain with a suitable example. 2. What are the various uses of final keyword in java? An abstract method can not be declared final. Why? 3. Differentiate between Abstract class and Interface. What do you mean by Functional interface and Lambda Expression?  ...

OLA-UBER Problem

Create two interfaces OLA and UBER both having a method public static Cab getCab() which returns the Cab object where Cab is a nested class inside OLA and UBER. Cab must have attributes cab_number and driver_name. A user rides 5 times using cabs of OLA and UBER randomly which are stored in an array. Now implement a method which should display the name of the driver and the company name i.e. OLA/UBER when the valid cab_number is entered by the user. Display "Invalid CAB details" when the cab_number entered by the user is incorrect.