This question is related to java Define the following terms
This question is related to java:
Define the following terms and give a java code (example) for each of the first two concepts: Inheritance: Polymorphism: Superclass: Subclass:Solution
Inheritance is a method by which an object requires properties of another object.it allows creation of heirarchal classifications .using inheritance a class can be derived from another class.The class which is inherited is called a Super class.(also called parent class or base class) and the class which does the inheriting is called subclass(also called child class or derived class).the sub class can inherit some or all the features from it parent.it can also add its own features.in order to inherit a class ,we simply incorporate the definition of one class into another using \'extends \'keyword\'.
Example: class test
{
int x,y;
test(int p,int q)
{
x=p;
y=q;
}
void display()
{
system.out.println(\"x and y:\" +x+\"\"+y);
}
}
class test1 extends test
{
int z;
test 1(int p,int q,int r)
{
super(p,q);
z=r;
}
void display(string msg)
// overloading display
{
system.out.println(msg +z);
}
}
class overloaded 1
{
public static void main(string args[])
{
test 1 t1=new test1(5,6,7);
t1.display(\"z:\");
//method display() in subcalass is called t1.display();
t1.display();
//method display() in super class is called
}
}
......................................................................................................................................................................
polymorphism: The ability to take many forms .polymorphism is a java feature that allows one interfcae to be used many times for multiple purposes.the concept polymorpohism is often expressed as \"one interface multiple methods\" .this means that it is possible to create an interface that can be used for a group of related activities .with the use of polymorphism the complexit is reduced .it is the job of the compiler to select an appropriate action.(i.e methods) which best suits to each situation .hence ,the programmer is free from selection.
Example: public interface veg{}
public class Animal{}
public classs Lion extends Animal implements veg{}

