You are on page 1of 1

‎Definition.

‎ variable is a container which


A
‎holds the value while the Java
‎program is executed. A variable is
‎assigned with a data type.

‎Variables ‎

‎declared inside the body of the


‎Local Variable ‎method is called local variable.

‎ ariable declared inside the class


v
‎but outside the body of the
‎Instance variable ‎method
‎Types of Variables
‎Concept

I‎ t cannot be local. You can create


‎a single copy of the static
‎variable and share it among all
‎Static variable ‎the instances of the class.

‎ rimitive data types: The


P
‎primitive data types include
‎boolean, char, byte, short, int,
‎1 ‎Basic ‎long, float and double.
‎1 ‎

‎ on-primitive data types: The


N
‎Data Types
‎non-primitive data types include
‎Classes, Interfaces, and Arrays.
‎2 ‎

i‎f statements
‎switch statement

‎Decision making ‎ ecision-making statements evaluate the


D
‎Boolean expression and control the
‎program flow depending upon the result
‎of the condition provided.

t‎ o execute the block of code repeatedly


‎while some condition evaluates to true.

‎ o while loop
d
‎Looping ‎while loop
‎Control Statement ‎for loop
‎for-each loop

‎ reak statement
b
‎continue statement

‎Jump Statement J‎ ump statements are used to transfer the


‎control of the program to the specific
‎statements.

‎Concept

‎ he main aim of object-oriented


T
‎programming is to implement
‎real-world entities, for example,
‎object, classes, abstraction,
‎loads code
‎inheritance, polymorphism, etc.
‎ ‎Verifies code
‎1 ‎Definition ‎
‎Execute code

‎provides runtime environment

‎ Ways to initialize object


3
‎There are 3 ways to initialize object in Java.

‎ ny entity that has state and behavior is
A ‎---By reference variable
‎known as an object. For example, a chair, ‎---By method
‎pen, table, keyboard, bike, etc. It can be ‎---By constructor
‎2 ‎Object ‎physical ‎

‎ ollection of objects is called class. It is a


C
‎2 ‎OOPs Methodology ‎logical entity.

‎A class can also be defined as a blueprint
‎from which you can create an individual
‎3 ‎Class ‎object.

‎ method is like a function which is used


a
‎to expose the behavior of an object.

‎Advantage of Method
‎Code Reusability
‎Code Optimization
‎4 ‎Method ‎

‎ he new keyword is used to allocate


T

‎PROGRAMMING ‎5 ‎new Keyword ‎memory at runtime.

‎IN JAVA -‎ --method is a block of code or collection


‎of statements or a set of code grouped
‎together to perform a certain task or
‎operation.
‎---It is used to achieve the reusability of
‎code. ---
‎---We write a method once and use it
‎many times.

‎ he most important method in Java is the


T
‎Definition
‎main() method.

‎Eg: public int sum(int a int b)

-‎ -Access specifier or modifier is the access


‎type of the method. It specifies the
‎visibility of the method. Java provides four
‎types of access specifier

‎ ublic: The method is accessible by all


P
‎classes when we use public specifier in our
‎application.

‎ rivate: When we use a private access


P
‎Access Specifier ‎specifier, the method is accessible only in
‎the classes in which it is defined.

‎ rotected: When we use protected access


P
‎specifier, the method is accessible within
‎the same package or subclasses in a
‎different package.

‎3 ‎Method
‎Return type is a data type that the
‎method returns. It may have a primitive
‎data type, object, collection, void, etc. If the
‎method does not return anything, we use
‎Return Type ‎void keyword.

‎ ethod Name: It is a unique name that is


M
‎used to define the name of a method. It
‎must be corresponding to the functionality
‎Method Name ‎of the method.

‎ arameter List: It is the list of parameters


P
‎separated by a comma and enclosed in
‎the pair of parentheses.

‎Parameter List ‎It contains the data type and variable


‎name. If the method has no parameter, left
‎the parentheses blank.

‎ ethod Body: It is a part of the method


M
‎declaration. It contains all the actions to be
‎performed. It is enclosed within the pair of
‎Method Body ‎curly braces.

‎ olymorphism means "many forms", and it


P
‎occurs when we have many classes that
‎are related to each other by inheritance.

‎ olymorphism uses those methods to


P
‎perform different tasks.

‎ here are two ways to overload the


T
I‎ f a class has multiple methods having ‎method in java
‎same name but different in parameters, it ‎
‎is known as Method Overloading. ‎By changing number of arguments
‎ ‎By changing the data type
‎Method overloading ‎ ‎
‎4 ‎Polymorphism
‎ ules:The method must have the same
R
I‎ f subclass (child class) has the same ‎name as in the parent class
‎method as declared in the parent class, it is ‎The method must have the same
‎known as method overriding in Java. ‎parameter as in the parent class.
‎ ‎There must be an IS-A relationship (
‎Method overriding ‎ ‎inheritance).

‎ sage of Java super Keyword


U
‎--super can be used to refer immediate
‎ he super keyword in Java is a reference
T ‎parent class instance variable.
‎variable which is used to refer immediate ‎--super can be used to invoke immediate
‎parent class object. ‎parent class method.
‎ ‎--super() can be used to invoke immediate
‎Super Keyword ‎ ‎parent class constructor

You might also like