Home > DeveloperSection > Blogs > IN OOPS NEXT COME CLASSES


Java OOPS 
10 Comment(s)
 620  View(s)
Rate this:
Hope my earlier explanation about object is understood to everyone.
Now, i am going to discuss next about classes.
let us take e.g. from real world i.e. Car. here, car has many types but kind is same.All of the same make and model.
Each Car is made of same prototype or blueprint and therefore, contains same components.
In OOPS, we can say car is an instance of the class of the objects knows as"CARS".
so, class is the prototype from which individual objects are created. 
I repeat my earlier e.g. over here i.e. class car which i posted in earlier post.
i just want to explain that the field cadence, speed, gear , music system volume all represents the state & the method change cadence, change gear, change speed, change volume defines its interaction from outside world.
Here, you may noticed that car doesn't contain a main method, that is because it just a prototype not a complete application.
In next post i will explain this prototype with e.g.


By Mayank Tripathi on   one year ago
Yes, class is a blueprint for objects.

More general we can say that a class is a group of objects which have similar behavior and characteristics.
Abstract Explanation:
For e.g. as in Schools classes are there which categories the syllabus for students accordingly. In 1st Class All the students have same thing to study ABCD
While all 5th class student have comman syllabus to study Arithmetic operations
While all 10 class student have same syallbus to study Calculus.

i.e. people with common properties and characteristics are grouped in Classes 

Real world Explanation:
Suppose you  what to buy a Car, when u think about car you think in a abstract way you think about the functions and conman structure which provided by car\
But when u think about specific Car : Black BMW, Red Color Audi or any other model of your choice, these are real entities not abstract

i.e Car is class and BMW and Audi are the different objects of the Car class

Hope these explanations help you sink the concepts of classes in Java

Your going good, Keep on learning and posting new stuffs and thoughts!!


By ANkita gupta on   one year ago
now , here i explained class with e.g.,
class car {
public static void main (string[]arg)
car objects
car Mercedes = new Car();
car BMW = new Car();
now, interact behavior on state i.e. invoke methods on object


o/p will be;
cadence=50, gear=2; speedup= 10; music volume=15
cadence=40; gear=3; speedup= 20; music volume=18

Correct Way!!

By Mayank Tripathi on   one year ago
First of all instead of car1 and car2 you need to use Mercedes and BMW(the objects you have created) to access class members using dot operator.

First create a class Car consists of its properties and methods and then create a Test class to create car objects and test the methods there.

Car Class:

public class Car{
//state or field declarations
double cadence
double speed
int gear
int musicSystemVolume
//method Declarations
public void changeCadence(double cadence){
 this.cadence = cadence
public void changeSpeed(double speed){
 this.speed = speed
public voidchangeGear(int gear){
 this.gear = gear
 public voidchangeVolume(int musicSystemVolume){
 this.musicSystemVolume = musicSystemVolume
public void printStates(){
System.out.print("cardence="+ this.cadence +", ");
System.out.print("gear="+ this.gear +", ");
System.out.print("speedup="+ this.speed +", ");
System.out.print("music volume="+ this.musicSystemVolume);
//End of class

CarTest Class:
public class CarTest{
public static void main(String args[]){
//create objects of car class 
Car BMW = new Car();
Car Mercedes = new Car();
// interact behavior on state i.e. invoke methods on object
//End of class

o/p will be;
cadence=50, gear=2; speedup= 10; music volume=15
cadence=40; gear=3; speedup= 20; music volume=18

Ankita  try to learn and follow the correct assumptions and standards provided by OOPS
All the best !!

class e.g.

By ANkita gupta on   one year ago
thanks for correcting me.


By ANkita gupta on   one year ago

suggestion for class student

By ANkita gupta on   one year ago
I struct in making program on class student.
problem is that there are many states i.e. color, name, age, class, gender
behavior i.e. writing, reading, listening, hearing, speaking.
so, i want to ask how to assign local variable for such state which interact with outside world.
If we assume that student is normal then, its behavior got change, then it is easy to make program.
please, suggest in comment with suitable ans.

Sudent class

By Mayank Tripathi on   one year ago
Ankita can you provide me your code, then i can implement your issue and explain you

student class

By ANkita gupta on   one year ago
can you share your code , i want to see how you implement local variable for this prob.

student class

By Mayank Tripathi on   one year ago
Ankita i wouldn't understand you problem, but local variables are local to methods only you can't access them outside the method. However, your can access instance variables the better way is to make them private and provide getter- setter methods to access them.

As per Student class implementation here is a simple sample for your learning:

Student Class:

public Class Student{
//state or field decelerations
String color
String name;
int age;
int studentClass
char gender;

Student(String color,String name,int age,int studentClass,char gender){
this.color = color;
this.name = name;
this.age = age;
this.studentClass = studentClass;
this.gender = gender;

//method implementations
public void writing(String expression){
System.out.println( this.name + "is writing " + expression);

public void reading(String expression){
System.out.println( this.name + "is reading " + expression);

public void listening(String music){
System.out.println( this.name + "is listening " + music);

public void hearing(String expression){
System.out.println( this.name + "is hearing " + expression);

public void speaking(String expression){
System.out.println( this.name + "is speaking " + expression);

//End of the class

StudentTest Class:

public class StudentTest{

public static void main(String[] args){

//Create objects
Student ravi = new Student("White", "Ravi", 22, 12, 'M');
Student swati = new Student("Black", "Swati", 18, 10, 'F');

//Acess methods and instance variable using Student object
System.out.println(ravi. name + " is  " + ravi.age + "  years old and studies in "+ ravi.studentClass +" class " );

System.out.println(swati. name + " is  " + swati.age + " old and studies in " + swati.studentClass + " class " );

//End of class


Ravi is writing Stories
Ravi is reading Newspapaer
Ravi is listening Pop
Ravi is 22 years old and studies in 12 class
Swati is writing Poems
Swati is reading English
Swati is listening Rock
Swati is 18 years old and studies in 10 class

Hope this will help you understand classes and communication between object and class members!!

student class

By ANkita gupta on   one year ago
by this way i already done, anyways thanks, but i want to know is there any case if he/she is abnormal then what we will do? is it possible to make such programs? 

Don't want to miss updates? Please click the below button!

Follow MindStick