Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package one;
- public class One
- {
- public static void main(String[] args)
- {
- Two tw = new Two();
- Two tw1 = new Two("alvi","01761900889",20.00,5000.00,1.00);
- Three th = new Three();
- Three th1 = new Three("alvi","01761900889",20.00,5000.00,1.00);
- /* set using setter and getter method */
- /*
- tw.setname("alvi");
- tw.setmobno("01761900889");
- tw.setage(20.00);
- tw.setbasic(5000); // FOR TWO CLASS
- th.setbasic(5000); // FOR THREE CLASS
- // IF WE DONT USE tw.setbasic(); and th.setbasic(); two times
- // THE VALUE OF BASIC WONT BE CHANGD SECOND TIME . THAT IS IT WILL
- // BE CHANGED TO 5000 FIRST TIME BUT IT WILL BE REMAIN IN INITIAL
- // VALUE 100 SECOND TIME
- tw.setyear(1.00);
- */
- /* we must use parameterized constructor , otherwise the basic wont
- be changed
- */
- System.out.println(tw1.salary());
- //System.out.println(th.salary());
- System.out.println(th1.salary());
- //System.out.println(tw.salary());
- }
- }
- public class Two
- {
- public String name = "A";
- public String mobno = "1761900889";
- public double age = 30.00;
- public double basic = 100.00 ;
- public double year = 1.00;
- Two()
- {
- }
- Two(String name,String mobno,double age,double basic,double year)
- {
- this.name=name;
- this.mobno=mobno;
- this.age=age;
- this.basic=basic;
- this.year=year;
- }
- public void setname(String name)
- {
- this.name=name;
- }
- public void setmobno(String mobno)
- {
- this.mobno=mobno;
- }
- public void setage(double age)
- {
- this.age=age;
- }
- public void setbasic(double basic)
- {
- this.basic=basic;
- }
- public void setyear(double year)
- {
- this.year=year;
- }
- public String getname()
- {
- return name;
- }
- public String getmobno()
- {
- return mobno;
- }
- public double getage()
- {
- return age;
- }
- public double getbasic()
- {
- return basic;
- }
- public double getyear()
- {
- return year;
- }
- public double salary()
- {
- double s = basic * 2 * year ;
- return s;
- }
- }
- public class Three extends Two
- {
- public double increament = ((basic*75)/100);
- Three()
- {
- super();
- }
- Three(String name,String mobno,double age,double basic,double year)
- {
- this.name=name;
- this.mobno=mobno;
- this.age=age;
- this.basic=basic;
- this.year=year;
- }
- public double salary()
- {
- double sa = ( (basic + increament)* 2 * year ) ;
- return sa;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment