Class - MethodCalling - ObjectCreation by Kunal Sir Official
Class - MethodCalling - ObjectCreation by Kunal Sir Official
What Is Class?
1. Class is a different type of logical entity.
2. It is used to design template or blueprint.
3. With class keyword we can design class in java.
1) Inbuild Class: -
This type of classes predefined by the java community.
For Example:
2) Custom Class: -
This type of classes design from our own purposes.
For Example:
{ {
} }
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052, Mobile No.- 8888022204
by Kunal Sir
Point 1: - When class is public then class name and file name must be
same.
For example: -
public class A
Point 2: - When class is not public then class name and file name can be
different.
For example: -
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052, Mobile No.- 8888022204
by Kunal Sir
class B
A.java
Create a class named "A":
public class A
System.out.println(“Welcome to CJC”);
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052, Mobile No.- 8888022204
by Kunal Sir
Run: java A
Types of Methods: -
There are Four types of methods:
Simple Method: -
Syntax: - AccessModifier ReturnType MethodName()
For example: -
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052, Mobile No.- 8888022204
by Kunal Sir
For example: -
return --;
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052, Mobile No.- 8888022204
by Kunal Sir
For example: -
return 10;
return x;
For example: -
return x;
Object Creation: -
Syntax: -
ClassName referencevariable = new ClassName();
For example: -
A a = new A ();
Where:
A -- ClassName
a -- ReferenceVariable / Object
new -- Keyword
Method Calling: -
Syntax: -
referencevariable.methodName();
For example: -
a.m1();
Where:
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052, Mobile No.- 8888022204
by Kunal Sir
a -- ReferenceVariable / Object
m1 -- Method Name (m1—Method1)
System.out.println(“M1 method”);
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052, Mobile No.- 8888022204
by Kunal Sir
Stop, Near, 1st Floor, Above Rupam Sweets/ Priyanka Collections Building Vikas Mitra Mandal Chowk
Road, Karve Nagar, Pune, Maharashtra 411052, Mobile No.- 8888022204