-
Notifications
You must be signed in to change notification settings - Fork 0
/
OOPs.java
45 lines (39 loc) · 1.84 KB
/
OOPs.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
public class OOPs {
}
// OBJECT ORIENTED PROGRAMMING
// Object- Properties and behaviour
// Class
// #1
// Whatever we do in Java, we do it in a class.
// A class is a user-defined blueprint or prototype from which objects are created.
// - In a class, we have methods and variables.
// - Class will be created in the same java file.
// - We can create any number of classes in a program.
// - Class does not occupy memory.
// Syntax of a class:-
// class classname
// {
// methods, variables
// }
// #2
// - Every object has two things: properties and methods.
// - When an object of a class is created, the class is said to be instantiated. All the instances share the attributes and the behavior of the class.
// - Action will be done with the help of methods.
// - We need to specify the access to methods. We will specify it as public if we want it to be called from anywhere else.
// - If we want the method to return any value then we need to specify its return type like int for Integer type values.
// - As Java is a statically typed language so you have to specify the return type in it.
// Syntax of method:-
// = access modifier return type method name()
// public int add()
// {
// statement;
// }
// #3
// - We need an object to call a method from a different class.
// - Creating an object:-
// classname reference variable= new classname();
// - reference variable is used to tell that this variable is made to establish a reference between a class.
// - new keyword is used to tell that we have to utilise the space for an object.
// - We can call a method by using the reference variable of the object.
// - We have to pass the values if we want some operations to be on them.
// - We also have to accept values in a method as well if we pass some values. For this, we have to specify parameters in a method based on the type of passed values.