- Class
- Blueprint for object
- A Programming construct which defines properties and behaviors for Object.
- In java everything is encapsulated under classes.
- use keyword “class” to initial class
- Object
- Instance of class
- any real life entity which has properties and behaviors
- use keyword “new” to create object
- template for object
Example :
// www.learning2night.com
#include<iostream>
using namespace std;
class Dog{
public:
// properties
int numberLeg;
int eye;
// behaviors
// dog can walk
void walk(){
cout<<"Dog Walk"<<endl;
}
// dog can run
void run(){
cout<<"Doc Run !"<<endl;
}
// it cave more properties and behaviors
};
int main(){
Dog d;// create object d from class Dog
d.walk();
d.run();
return 0;
}
Output:
Dog Walk Doc Run !