Solved programming problem

Inheritance Basic Problem 2 in Java.

Source code

Main Method: 

 
package playsound;

public class PlaySound {

    public static void main(String[] args) {

        ////create object

        Square s = new Square();

        Circle c = new Circle();

        s.printText();

        c.printText();

        s.test();

        /// s.test1();  this methos is private so we cant call this method like that

    }

}

Print Class:

package playsound;

public class Print

{

   public void printText()

   {

       System.out.println("Code to HaveN");

   }

   protected void test()

   {

       System.out.println("Protected Method Called");

   }

 

  private void test1()

   {

       System.out.println("Private  Method Called");

   }

}

Circle Class:

package playsound;

public class Circle extends Print

{

    @Override

    public void printText()

    {

        System.out.println("Over Riding ");

    }

}

Square Class:

package playsound;

public class  Square extends Print

{

    ///nothing here ;)

}

Output

Code to HaveN

Protected Method Called

Over Riding

Join the discussion

Add your comment