Shivaji Maharaj Jayanti Alight Motion Video Editing | Getting Started With Java Classes With Example | Technical Sham


 नमस्कार मित्रांनो Technical Sham च्या एका नवीन आणि इंटरेस्टिंग ब्लॉग मध्ये तुमचे सहर्ष स्वागत आहे. हॅलो फ्रेंड्स या ब्लॉगमध्ये तुम्हाला Java प्रोग्रामिंग बद्दल शिकायला भेटेल तसेच माझे  YouTube चैनल आहे, त्यामध्ये मी व्हिडिओ एडिटिंग करतो त्यासाठी जे काही मटेरियल आहे ते तुम्हाला या साईट वरती मिळून जाईल खाली डाउनलोड ऑप्शन मिळेल स्क्रोल करा तिथून तुम्ही हे सर्व मटेरियल डाउनलोड करून घ्या तर जर तुम्ही Programmers/Coder असाल तर फक्त प्रोग्रामिंग Content कडे लक्ष द्या आणि जर एडिटर असाल तर खाली मटेरियल दिला असेल मटरेल दिला आहे तिथून तुम्ही म्हटले डाऊनलोड करा.

Scroll Now 👇🏻👇🏻

 A Simple Class :

Let’s begin our study of the class with a simple example. Here is a class called Box that defines three instance variables: width, height, and depth. Currently, Box does not contain any methods (but some will be added soon).

class Box {
    double width;
    double height;
    double depth;
}


After this statement executes, mybox will be an instance of Box. Thus, it will have “physical” reality. For the moment, don’t worry about the details of this statement.

As mentioned earlier, each time you create an instance of a class, you are creating an object that contains its own copy of each instance variable defined by the class. Thus, every Box object will contain its own copies of the instance variables width, height, and depth. To access these variables, you will use the dot (.) operator. The dot operator links the name of the object with the name of an instance variable. For example, to assign the width variable ofmybox the value 100, you would use the following statement:

mybox.width = 100;

This statement tells the compiler to assign the copy of width that is contained within the mybox object the value of 100. In general, you use the dot operator to access both the instance variables and the methods within an object.


Here is a complete program that uses the Box class:

/* A program that uses the Box class.
Call this file BoxDemo.java
*/
class Box {
double width;
double height;
double depth;
}
// This class declares an object of type Box.
class BoxDemo {
public static void main(String args[]) {
Box mybox = new Box();
double vol;
// assign values to mybox's instance variables
mybox.width = 10;
mybox.height = 20;
mybox.depth = 15;
// compute volume of box
vol = mybox.width * mybox.height * mybox.depth;
System.out.println("Volume is " + vol);
}
}


    You should call the file that contains this program BoxDemo.java, because the main( ) method is in the class called BoxDemo, not the class called Box. When you compile this program, you will find that two .class files have been created, one for Box and one for BoxDemo. The Java compiler automatically puts each class into its own .class file. It is not necessary for both the

    Box and the BoxDemo class to actually be in the same source file. You could put each class in its own file, called Box.java and BoxDemo.java, respectively.

To run this program, you must execute BoxDemo.class. When you do, you will see the following output:

Volume is 3000.0

    As stated earlier, each object has its own copies of the instance variables. This means that if you have two Box objects, each has its own copy of depth, width, and height. It is important to understand that changes to the instance variables of one object have no effect on the instance variables of another. For example, the following program declares two Box objects:

// This program declares two Box objects.

class Box {
double width;
double height;
double depth;
}
class BoxDemo2 {
public static void main(String args[]) {
Box mybox1 = new Box();
Box mybox2 = new Box();
double vol;
// assign values to mybox1's instance variables
mybox1.width = 10;
mybox1.height = 20;
mybox1.depth = 15;
/* assign different values to mybox2's
instance variables */
mybox2.width = 3;
mybox2.height = 6;
mybox2.depth = 9;
// compute volume of first box
vol = mybox1.width * mybox1.height * mybox1.depth;
System.out.println("Volume is " + vol);
// compute volume of second box
vol = mybox2.width * mybox2.height * mybox2.depth;
System.out.println("Volume is " + vol);
}
}


The output produced by this program is shown here:

Volume is 3000.0
Volume is 162.0   

As you can see, mybox1’s data is completely separate from the data contained in mybox2.


Editing Friends  You Can Download Our Materials For Free !!!


Join Telgram Channel :-



सर्व मटेरियल साठी खाली download करा... 👇









Only Editing Friends खालील व्हिडिओ पुर्ण बघा. 👇🏻




मित्रांनो आपल्याला Instagram वरती नक्की follow करा.


FOLLOW ON INSTAGRAM 

SUBSCRIBE YOUTUBE CHANNEL


Thanks For Visit My Website.. 🙏

Post a Comment

Previous Post Next Post