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
ππ
ReplyDeleteThank you
DeleteThanks
DeleteWell done,, good work π
DeleteGood concept
ReplyDeleteGood content...keep writing
ReplyDeleteThank you yes I will keep writing the new concepts
DeleteGood work π
ReplyDeleteThank you so much
DeleteContentππ
ReplyDeleteThank you I will try to write more concepts
DeleteInformative
ReplyDeleteThank you
DeleteThank you for your appreciation
ReplyDeleteGood work..
ReplyDeleteGood one
ReplyDeleteNicely Explained✌
ReplyDelete