Create an application that is composed of at least 2 classes in addition to the startup class.One of the classes is to be a subclass derived from the other. The subclass is to have at least 3 constractors which will be called during the creation of 3 subclass objects.In the example shown, the subclass student has a default constractor, a constractor with one string argument, and a constractor with a string argument
giving the student's name and integer argument giving an ID number. (File must be save as: Assigment06.java)
import javax.swing.JOptionPane;
class Startup
{
public String n;
public int r;
}
class Sub extends Startup
{
Sub()
{
//JOptionPane.showMessageDialog(null,"For default constructor\n");
n="Blank name";
r=0;
}
Sub(String s)
{
//JOptionPane.showMessageDialog(null,"For one string constractor\n");
n=s;
r=0;
}
Sub(String s,int a)
{
n=s;
r=a;
}
void print()
{
JOptionPane.showMessageDialog(null,"Name : "+n+"\nRoll : "+r);
}
}
class Assigment06
{
public static void main(String args[])
{
Sub a,b,c;
String s1,s2;
int n;
a=new Sub();
a.print();
s1=JOptionPane.showInputDialog("Name : ");
b=new Sub(s1);
b.print();
s1=JOptionPane.showInputDialog("Name : ");
s2=JOptionPane.showInputDialog("Roll : ");
n=Integer.parseInt(s2);
c=new Sub(s1,n);
c.print();
System.exit(0);
}
}
////////////////////////////////////////////
Copy & paste this code in your TC & run, then you will get output.......
If you have any problem please comment below.........
Copy & paste this code in your TC & run, then you will get output.......
If you have any problem please comment below.........