Computer Science, asked by rajusurjit6671, 1 year ago

Create a base class fruit wch has name ,taste and size as its attributes. a method called eat() is created wch describes the name of the fruit and its taste. inherit the same in 2 other class apple and orange and override the eat() method to represent each fruit taste.

Answers

Answered by Manindersingh11
2
in python:

class fruit:
def__init__(self,taste,size,name):
self.taste=taste
self.name=name
self.size=size
def eat(self):
print(name,taste)

class apple(fruit):
def__init__(self,taste,size,name):
super().__init__(taste,size,name)
def eat(self):
print(name,taste):

class orange(apple):
def__init__(self,taste,size,name):
super().__init__(taste,size,name)
def eat(self):
print(name,taste):
Answered by franktheruler
3

Answer:

java

class fruit

{    

  protected char name, taste, size  ;

 scanner sc = new scanner ( system. in );

  public void eat ( ) // overridden method.

 {

       scanner sc = new scanner ( system. in );

       system. out. println ( "enter the name of the fruit " ) ;

       name = nextChar ( ) ;

       system. out. println ( " please provide the taste of the fruit " ) ;

       taste = nextChar ( ) ;

       system. out. println ( " Name of the fruit is: " + name ) ;

       system. out. println ( " Taste of the fruit is: " + taste ) ;  

    }

}

class apple extends fruit

{

  void eat ( ) // overriding method

  {

       system. out. println ( " Name of the fruit is Apple " ) ;

       system. out. println ( " Taste of the fruit is sweet " ) ;

    }  

}

class orange extends fruit

{

   public void eat ( ) // overriding method

  {

       system. out. println ( " Name of the fruit is Orange " ) ;

       system. out. println ( " Taste of the fruit is sour " ) ;

    }

}

class main_class

{

 public static void main ( string args )

  {

    apple A = new apple ( ) ;

     A . eat ( ) ;

    orange O = new orange ( ) ;

    O . eat ( ) ;

  }

}

Similar questions