Java Class concept
Class
A class is a blueprint or prototype from which objects are created. Class that contains data type, Object, function methods, properties, Classes and constructor.
Example:
For example our college, Our college contain different different classes and classes contain student.
Programming Language Example:
class MyClass{
String name= "";
String address= "";
int age= 0;
void setName(String name) {
this.name = name;
}
void setAddress(String address) {
this.address = address;
}
void setAge(int age) {
this.age = age;
}
void print() {
System.out.println(name +" "+Address+" "+age);
}
}
class MyClassDemo {
public static void main(String[] args) {
// Create two different objects
MyClass student1 = new MyClass();
MyClass student2 = new MyClass();
// Invoke methods on those objects
student1.setName("x");
student1.setAddress("address");
student1.setAge(20);
student1.print();
student2.setName("Y");
student2.setAddress("address2");
student2.setAge(22);
student2.print();
}
}
A class is a blueprint or prototype from which objects are created. Class that contains data type, Object, function methods, properties, Classes and constructor.
Example:
For example our college, Our college contain different different classes and classes contain student.
Programming Language Example:
class MyClass{
String name= "";
String address= "";
int age= 0;
void setName(String name) {
this.name = name;
}
void setAddress(String address) {
this.address = address;
}
void setAge(int age) {
this.age = age;
}
void print() {
System.out.println(name +" "+Address+" "+age);
}
}
class MyClassDemo {
public static void main(String[] args) {
// Create two different objects
MyClass student1 = new MyClass();
MyClass student2 = new MyClass();
// Invoke methods on those objects
student1.setName("x");
student1.setAddress("address");
student1.setAge(20);
student1.print();
student2.setName("Y");
student2.setAddress("address2");
student2.setAge(22);
student2.print();
}
}
Comments
Post a Comment