1.If we want to add a new Crow class,first of all we have to observe what is the type of Crow
class.Crow is a type of Bird.As is having the features of the Bird we have to make the Crow class
as a subclass to Bird class.
2.Actually we kept the bodyTemperature variable in Reptile class.But we know every living
thing has a body temperature.So we have to use that variable in the super class or parent class of
all the classes.
So we have to put that bodyTemperature varuable in the animal class(This is the super class of
all te classes here).So that all animals will have bodytemperature.Means the subclasses of the
Animal class like Reptile class and Bird class will have body temperature.
If we use bodyTemperature in Reptile class.We can use it only in the Reptile class and its
subclasses.We can use it the Bird Class and its sub classes.
3)If we want to make an Ostrich class as a subclass to Bird class,and also if we want to disable
the fly() method of Bird class in Ostrich class we have to override the fly() method in the Ostrich
class and we dont have to provide any implementation for that overridden fly() method .So that if
we call the fly() method in Ostrich it will not do anything or we can write
UnsupportedOperationException.
class Ostrich extends Bird
{
@Override
fly()
{
}
}
_______________( OR )___________________
class Ostrich extends Bird
{
@Override
fly()
{
UnsupportedOperationException();
}
}
_________________________________________
Solution
1.If we want to add a new Crow class,first of all we have to observe what is the type of Crow
class.Crow is a type of Bird.As is having the features of the Bird we have to make the Crow class
as a subclass to Bird class.
2.Actually we kept the bodyTemperature variable in Reptile class.But we know every living
thing has a body temperature.So we have to use that variable in the super class or parent class of
all the classes.
So we have to put that bodyTemperature varuable in the animal class(This is the super class of
all te classes here).So that all animals will have bodytemperature.Means the subclasses of the
Animal class like Reptile class and Bird class will have body temperature.
If we use bodyTemperature in Reptile class.We can use it only in the Reptile class and its
subclasses.We can use it the Bird Class and its sub classes.
3)If we want to make an Ostrich class as a subclass to Bird class,and also if we want to disable
the fly() method of Bird class in Ostrich class we have to override the fly() method in the Ostrich
class and we dont have to provide any implementation for that overridden fly() method .So that if
we call the fly() method in Ostrich it will not do anything or we can write
UnsupportedOperationException.
class Ostrich extends Bird
{
@Override
fly()
{
}
}
_______________( OR )___________________
class Ostrich extends Bird
{
@Override
fly()
{
UnsupportedOperationException();
}
}
_________________________________________.
1.If we want to add a new Crow class,first of all we have to observe.pdf
1. 1.If we want to add a new Crow class,first of all we have to observe what is the type of Crow
class.Crow is a type of Bird.As is having the features of the Bird we have to make the Crow class
as a subclass to Bird class.
2.Actually we kept the bodyTemperature variable in Reptile class.But we know every living
thing has a body temperature.So we have to use that variable in the super class or parent class of
all the classes.
So we have to put that bodyTemperature varuable in the animal class(This is the super class of
all te classes here).So that all animals will have bodytemperature.Means the subclasses of the
Animal class like Reptile class and Bird class will have body temperature.
If we use bodyTemperature in Reptile class.We can use it only in the Reptile class and its
subclasses.We can use it the Bird Class and its sub classes.
3)If we want to make an Ostrich class as a subclass to Bird class,and also if we want to disable
the fly() method of Bird class in Ostrich class we have to override the fly() method in the Ostrich
class and we dont have to provide any implementation for that overridden fly() method .So that if
we call the fly() method in Ostrich it will not do anything or we can write
UnsupportedOperationException.
class Ostrich extends Bird
{
@Override
fly()
{
}
}
_______________( OR )___________________
class Ostrich extends Bird
{
@Override
fly()
{
UnsupportedOperationException();
}
}
_________________________________________
Solution
2. 1.If we want to add a new Crow class,first of all we have to observe what is the type of Crow
class.Crow is a type of Bird.As is having the features of the Bird we have to make the Crow class
as a subclass to Bird class.
2.Actually we kept the bodyTemperature variable in Reptile class.But we know every living
thing has a body temperature.So we have to use that variable in the super class or parent class of
all the classes.
So we have to put that bodyTemperature varuable in the animal class(This is the super class of
all te classes here).So that all animals will have bodytemperature.Means the subclasses of the
Animal class like Reptile class and Bird class will have body temperature.
If we use bodyTemperature in Reptile class.We can use it only in the Reptile class and its
subclasses.We can use it the Bird Class and its sub classes.
3)If we want to make an Ostrich class as a subclass to Bird class,and also if we want to disable
the fly() method of Bird class in Ostrich class we have to override the fly() method in the Ostrich
class and we dont have to provide any implementation for that overridden fly() method .So that if
we call the fly() method in Ostrich it will not do anything or we can write
UnsupportedOperationException.
class Ostrich extends Bird
{
@Override
fly()
{
}
}
_______________( OR )___________________
class Ostrich extends Bird
{
@Override
fly()
{
UnsupportedOperationException();
}
}
_________________________________________