JAVA OBJECT CREATION

 

 Today we will see how the objects mentioned in the previous article are created in Java programs.



First of all, we need to have a Java class to create objects in Java. Because only a Java class can be changed as a Java object.

For example, we are told to create a system to enter the data of people working in a workplace. So, if we are asked to create a system for that, first we need to create a template so that it is easy to enter the data. That is, a Java class should be created.

  It can be done like this.

class Worker{

        String name;

        int age;

        int dob;

        String address;

   

       public void Getdata(){

       }

        Public void showdata(){

        }


}


Then we can use that Java class to create separate objects for each person, through which we can get the data needed by the main system. As follows,


class System{

    Worker saman =new worker();

     saman.getdata();

     saman.showdata();


    Worker sunil =new worker();

     sunil.getdata();

     sunil.showdata();


}

In this way we can create Java objects in Java programs.


No comments:

Post a Comment

Pages