Saturday 28 July 2012

Single inheritance example program


class employee
{
        private int eno;
        private String ename;
        public void setemp(int no,String name)
        {
                eno = no;
                ename = name;
        }
        public void putemp()
        {
                System.out.println("Empno : " + eno);
                System.out.println("Ename : " + ename);
        }
}
class department extends employee
{
        private int dno;
        private String dname;
        public void setdept(int no,String name)
        {
                dno = no;
                dname = name;
        }
        public void putdept()
        {
                System.out.println("Deptno : " + dno);
                System.out.println("Deptname : " + dname);
        }
        public static void main(String args[])
        {
                department d = new department();
                d.setemp(100,"aaaa");
                d.setdept(20,"Sales");
                d.putemp();
                d.putdept();
        }
}
            super () -> Keyword used to call the base constructor;

10 comments:

  1. This program is Very easy to understand n easy to explain for some1 .........

    ReplyDelete
  2. I am technical writer of http://www.kriblog.com, I would like to thanks you for writing a very good article.

    ReplyDelete
  3. hi very easy step this program.I would like thank u ......





    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Very useful for beginners

    ReplyDelete
  6. Very useful for beginners

    ReplyDelete
  7. i found the solution through out this blog about Single inheritance with example program..java training in chennai

    ReplyDelete
  8. Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more .
    java training in chennai

    ReplyDelete
  9. Can you do with coomand line arguments

    ReplyDelete