Sunday, February 16, 2020

Introduction to Java Class


Basically, java class is group of objects and that all objects have same properties. It defines the shape and nature of an object. In java for implementation of any concept we must encapsulate that concept within a class. for create a class we have to decide a structure, once we decide the structure then it will be easy to write a class.
When we create a class that defines a new data type, this new type can be used to create object of that data type. thus, class is a template for an object and object is an instance of a class.
Every class is the combination of variables and methods. The data or variables defined within a class are called instance variable because each instance of the class contains its own copy of these variables. methods and variables defined within a class is called member of the class
In class declaration these components can include:
1.Modifier: A class can be public or has default access
2.Class name: The name should begin with capitalize letter
3. Body: The class body containing variables and methods, surrounded by braces { }.
structure of class
public class Dog {
public string breed;
public string color;
public string size;
public void run() {
system.out.println(I am running);
}
Public void bark() {
System.out.println(Wooh! Wooh!);
}
}
Public class main {
Public static void main(string[ ]args){
Dog dog1=new dog();
Dog1.breed=Beagle;
Dog1.size=40;
Dog1.color=Brownish White;
Dog1.run();
Dog1.bark();
}
}


Amarja Chede
K-10
















17 comments: