java what is purpose of declaring instance of class -


in java purpose of declaring instance of class? watching tutorial, , guy declared multiple instances of class.

suppose want drive car , make go faster pressing on accelerator pedal. doing so, you'll first need car. has design , build one. design in sense, engineering diagram depicting car must contain( pedals, steering, brake etc..) , shape of car, color of car etc..

so, above example, class nothing blueprint. architecture diagram, engineering diagram sort of. object defined instance of class, real model of car. design(aka blueprint aka class) model(object) must made make use of features braking, accelerating etc..

in java how class looks like:

public class <classname> { //variable declarations block  //method declarations block } 

and corresponding object created by:

<classname> objectname = new <classname>(); 

an example java program same:

public class test{     int age;    string name;    public void pup(){       system.out.println(age);       system.out.println(name);    }     public static void main(string args[]){       test test = new test();       test.age=5;       test.name="zooey";       test.pup();    } }  

here test class , has 2 variables declared, namely age , name. , has functionality called pup() print name , age.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -