SlideShare a Scribd company logo
Keywords of Java
By Harsh Jani
jani99harsh@gmail.com
Content
*It is refer to the object that is currently executed.
*It initializes the value of a variable
*Syntax = this.variable name;
*Example
* class xyz
* { int x;
* int y;
* xyz(int x, int y)
* {
* //if instance variable & parameter variable are different than no need of this keyword.
* this.x=x;
* this.y=y;
* }
* }
* class demo
* { public static void main(String args[])
* {
* xyz ob = new xyz(1,2);
* System.out.println(ob.x);
* System.out.println(ob.y);
*
* }
* }
* Output: 1
* 2
*Normally any of the class members can be accessed by using
object of its class, but it is possible to create a member that
can be used by itself without reference to a specific instance.
*It is possible by a static keyword.
*You can declare both method and variable to be static.
*If methods are declared static then
They can call other static methods.
They must only access static data.
They cannot refer to this or super keyword in any way.
*It provides static block.
*Example:
*
*class abc
*{
* static int a=10;
* static int b;
* // static variables
*
* static void printAll(int n)
* {
* System.out.println("N = "+n);
* System.out.println("A = "+a);
* System.out.println("B = "+b);
* }
* static
* {
* System.out.println("Static block executed");
* b=a*2;
* }
*}
*class demo
*{
* public static void main(String args[])
* {
* // static methods are directly called
without object
*
* printAll(5);
* }
*}
*Output: N = 5
* A = 10
* Static block executed
* B = 20
*Example – 2
* class teststatic
* {
* static int a = 10;
* static int b = 20;
* // static variables
* static void printA()
* {
* System.out.println("A = "+a);
* }
* }
* class staticinotherclass
* {
* public static void main(String args[])
* {
* // static methods are directly called without object
*
* teststatic.printA();
* System.out.println("B from other class = "+teststatic.b);
* }
* }
* Output: A = 10
* B from other class = 20
*
*Sometime we may wish to use superclass constructor
as they were implemented or we may wish to refer
super class variable into subclass where variables
with the same name as in superclass exists then java
provides a keyword super to solve above difficulties.
*You may use super keyword for
To call superclass constructor into a subclass
To refer superclass variable
* Example: To call superclass constructor into a subclass
* class box
* {
* int width,height,depth;
* // used when no parameter given
* box()
* {
* width=height=depth=10;
* }
* box(int a)
* {
* width=height=depth=a;
* }
* box(int w, int h, int d)
* {
* width=w;
* height=h;
* depth=d;
* }
* int volumeofbox
* {
* return(width*depth*height);
* }
* }
*class boxprise extends box
*{
* int prise;
* boxprise(int w, int h, int d, int p)
* {
* super(w,h,d);
* prise = p;
* }
*}
*class demo
*{
* public static void main(String args[])
* {
* box b1 = new box();
* System.out.println("Box1 volume is = "+(b1.volumeofbox));
* box b2 = new box(20);
* System.out.println("Box2 volume is = "+(b2.volumeofbox));
* boxprise b3 = new boxprise(3,4,5,600);
* System.out.println("Price of box is = "+(b3.priseofbox));
* System.out.println("Box3 volume is = "+(b3.volumeofbox));
* }
*
*}
*Output: Box1 volume is = 1000
Box2 volume is = 6000
Price of box is = 600
Box3 volume is = 60
*When we use super to call superclass constructor then super(); must be in
the first line of subclass.
* Example: To refer superclass variable
* class A
* {
* int a;
* }
* class B extends A
* {
* int a; int b;
* B(int x, int y, int z)
* {
* super.a=x;
* // assigns value to a variable of super class
* a=y;
* b=z;
* }
* void displayAll()
* {
* System.out.println("super.a =", +super.a );
* // access variable of super class in sub class
* System.out.println("A = ",+a);
* System.out.println("B = ",+b);
* }
* }
* class demo
* {
* public static void main(String args[])
* {
* B b1 = new B(10,20,30);
* b1.displayAll();
* }
* }
* Output: super.a = 10
* A = 20
* B = 30
*
To declared as constant
*Whenever you want to declare any variable whose
value cannot be changed at any time then you can do
this by declaring that variable as final.
*Using final you can define constant in java program
*Syntax = final datatype variablename = value;
*Example = final float PI = 3.14;
*Generally variable declared as final which are written
in uppercase.
*To prevent method overriding
* Write the final precede the method than it cannot be overridden.
* Method declared as final cannot be declared as an abstract method because it cannot be
overridden.
*Example:
* class xyz
* {
* final void printmessage()
* {
* System.out.println("hello");
* }
* }
* class B extends xyz
* {
* final void printmessage()
* {
* // error in the following line because method declared as final cannot be override
* System.out.println("hello");
* }
* }
*
*To prevent inheritance
*To do this write final precede the class declaration than it cannot
be inherited.
*Declaring class as final, indirectly declared all of its method as
final too.
*It is illegal to declare a class as both abstract and final.
*Example:
*final class A
*{
*}
*class B extends A // illegal
*{
*}
*A final class must full defined its methods with complete definition
because they are directly final and final method cannot be
redefine.
Keywords of java

More Related Content

What's hot

Java Programs
Java ProgramsJava Programs
Java Programs
vvpadhu
 
Functional programming with clojure
Functional programming with clojureFunctional programming with clojure
Functional programming with clojure
Lucy Fang
 
Quick python reference
Quick python referenceQuick python reference
Quick python referenceJayant Parida
 
Ppt on java basics1
Ppt on java basics1Ppt on java basics1
Ppt on java basics1
Mavoori Soshmitha
 
Interface
InterfaceInterface
Interface
vvpadhu
 
Groovy closures
Groovy closuresGroovy closures
Groovy closures
Vijay Shukla
 
string tokenization
string tokenizationstring tokenization
string tokenization
JayabalanRajalakshmi
 
Lecture - 5 Control Statement
Lecture - 5 Control StatementLecture - 5 Control Statement
Lecture - 5 Control Statement
manish kumar
 
Generics in .NET, C++ and Java
Generics in .NET, C++ and JavaGenerics in .NET, C++ and Java
Generics in .NET, C++ and Java
Sasha Goldshtein
 
C# Generics
C# GenericsC# Generics
C# Generics
Rohit Vipin Mathews
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
Mahmoud Samir Fayed
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
Shalabh Chaudhary
 
Bin Sorting And Bubble Sort By Luisito G. Trinidad
Bin Sorting And Bubble Sort By Luisito G. TrinidadBin Sorting And Bubble Sort By Luisito G. Trinidad
Bin Sorting And Bubble Sort By Luisito G. Trinidad
LUISITO TRINIDAD
 
Super keyword.23
Super keyword.23Super keyword.23
Super keyword.23myrajendra
 
Java this keyword ppt with example
Java this keyword ppt with exampleJava this keyword ppt with example
Java this keyword ppt with example
Pavan b
 
Computer programming 2 Lesson 15
Computer programming 2  Lesson 15Computer programming 2  Lesson 15
Computer programming 2 Lesson 15
MLG College of Learning, Inc
 

What's hot (20)

Java Programs
Java ProgramsJava Programs
Java Programs
 
Functional programming with clojure
Functional programming with clojureFunctional programming with clojure
Functional programming with clojure
 
Quick python reference
Quick python referenceQuick python reference
Quick python reference
 
Ppt on java basics1
Ppt on java basics1Ppt on java basics1
Ppt on java basics1
 
Interface
InterfaceInterface
Interface
 
Groovy closures
Groovy closuresGroovy closures
Groovy closures
 
Csharp_Chap03
Csharp_Chap03Csharp_Chap03
Csharp_Chap03
 
StringTokenizer in java
StringTokenizer in javaStringTokenizer in java
StringTokenizer in java
 
string tokenization
string tokenizationstring tokenization
string tokenization
 
Constructors
ConstructorsConstructors
Constructors
 
Lecture - 5 Control Statement
Lecture - 5 Control StatementLecture - 5 Control Statement
Lecture - 5 Control Statement
 
Generics in .NET, C++ and Java
Generics in .NET, C++ and JavaGenerics in .NET, C++ and Java
Generics in .NET, C++ and Java
 
C# Generics
C# GenericsC# Generics
C# Generics
 
Generics C#
Generics C#Generics C#
Generics C#
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
Bin Sorting And Bubble Sort By Luisito G. Trinidad
Bin Sorting And Bubble Sort By Luisito G. TrinidadBin Sorting And Bubble Sort By Luisito G. Trinidad
Bin Sorting And Bubble Sort By Luisito G. Trinidad
 
Super keyword.23
Super keyword.23Super keyword.23
Super keyword.23
 
Java this keyword ppt with example
Java this keyword ppt with exampleJava this keyword ppt with example
Java this keyword ppt with example
 
Computer programming 2 Lesson 15
Computer programming 2  Lesson 15Computer programming 2  Lesson 15
Computer programming 2 Lesson 15
 

Viewers also liked

L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variablesRavi_Kant_Sahu
 
Java notes 1 - operators control-flow
Java notes   1 - operators control-flowJava notes   1 - operators control-flow
Java notes 1 - operators control-flow
Mohammed Sikander
 
Top 10 things a fresh programmer should know - Dao Ngoc Khanh
Top 10 things a fresh programmer should know - Dao Ngoc KhanhTop 10 things a fresh programmer should know - Dao Ngoc Khanh
Top 10 things a fresh programmer should know - Dao Ngoc Khanh
DevDay.org
 
Becoming a Better Developer #WCA2
Becoming a Better Developer #WCA2Becoming a Better Developer #WCA2
Becoming a Better Developer #WCA2
Brian Richards
 
Learn Java language fundamentals with Unit nexus
Learn Java language fundamentals with Unit nexusLearn Java language fundamentals with Unit nexus
Learn Java language fundamentals with Unit nexus
Unit Nexus Pvt. Ltd.
 

Viewers also liked (6)

L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 
Java notes 1 - operators control-flow
Java notes   1 - operators control-flowJava notes   1 - operators control-flow
Java notes 1 - operators control-flow
 
Top 10 things a fresh programmer should know - Dao Ngoc Khanh
Top 10 things a fresh programmer should know - Dao Ngoc KhanhTop 10 things a fresh programmer should know - Dao Ngoc Khanh
Top 10 things a fresh programmer should know - Dao Ngoc Khanh
 
Sp rao abap
Sp rao abapSp rao abap
Sp rao abap
 
Becoming a Better Developer #WCA2
Becoming a Better Developer #WCA2Becoming a Better Developer #WCA2
Becoming a Better Developer #WCA2
 
Learn Java language fundamentals with Unit nexus
Learn Java language fundamentals with Unit nexusLearn Java language fundamentals with Unit nexus
Learn Java language fundamentals with Unit nexus
 

Similar to Keywords of java

Keyword of java
Keyword of javaKeyword of java
Keyword of java
Jani Harsh
 
Java2
Java2Java2
class object.pptx
class object.pptxclass object.pptx
class object.pptx
Killmekhilati
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
dbrienmhompsonkath75
 
Core Java
Core JavaCore Java
Core Java
Khasim Saheb
 
Java Concepts
Java ConceptsJava Concepts
Java Concepts
AbdulImrankhan7
 
Core java concepts
Core java concepts Core java concepts
Core java concepts
javeed_mhd
 
Exercises of java tutoring -version1
Exercises of java tutoring -version1Exercises of java tutoring -version1
Exercises of java tutoring -version1Uday Sharma
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
GaneshKumarKanthiah
 
Static variable
Static  variableStatic  variable
Static variable
vishal choudhary
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
Constructor&method
Constructor&methodConstructor&method
Constructor&method
Jani Harsh
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7
kamal kotecha
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
Muhammad Fayyaz
 
6.INHERITANCE.ppt(MB).ppt .
6.INHERITANCE.ppt(MB).ppt                    .6.INHERITANCE.ppt(MB).ppt                    .
6.INHERITANCE.ppt(MB).ppt .
happycocoman
 
Dynamic method dispatch
Dynamic method dispatchDynamic method dispatch
Dynamic method dispatch
yugandhar vadlamudi
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
BG Java EE Course
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
raksharao
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
tanu_jaswal
 

Similar to Keywords of java (20)

Keyword of java
Keyword of javaKeyword of java
Keyword of java
 
Java2
Java2Java2
Java2
 
class object.pptx
class object.pptxclass object.pptx
class object.pptx
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
 
Java Basic day-2
Java Basic day-2Java Basic day-2
Java Basic day-2
 
Core Java
Core JavaCore Java
Core Java
 
Java Concepts
Java ConceptsJava Concepts
Java Concepts
 
Core java concepts
Core java concepts Core java concepts
Core java concepts
 
Exercises of java tutoring -version1
Exercises of java tutoring -version1Exercises of java tutoring -version1
Exercises of java tutoring -version1
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Static variable
Static  variableStatic  variable
Static variable
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
Constructor&method
Constructor&methodConstructor&method
Constructor&method
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
6.INHERITANCE.ppt(MB).ppt .
6.INHERITANCE.ppt(MB).ppt                    .6.INHERITANCE.ppt(MB).ppt                    .
6.INHERITANCE.ppt(MB).ppt .
 
Dynamic method dispatch
Dynamic method dispatchDynamic method dispatch
Dynamic method dispatch
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
 

Recently uploaded

Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 

Recently uploaded (20)

Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 

Keywords of java

  • 1. Keywords of Java By Harsh Jani jani99harsh@gmail.com
  • 3. *It is refer to the object that is currently executed. *It initializes the value of a variable *Syntax = this.variable name;
  • 4. *Example * class xyz * { int x; * int y; * xyz(int x, int y) * { * //if instance variable & parameter variable are different than no need of this keyword. * this.x=x; * this.y=y; * } * } * class demo * { public static void main(String args[]) * { * xyz ob = new xyz(1,2); * System.out.println(ob.x); * System.out.println(ob.y); * * } * } * Output: 1 * 2
  • 5. *Normally any of the class members can be accessed by using object of its class, but it is possible to create a member that can be used by itself without reference to a specific instance. *It is possible by a static keyword. *You can declare both method and variable to be static. *If methods are declared static then They can call other static methods. They must only access static data. They cannot refer to this or super keyword in any way. *It provides static block.
  • 6. *Example: * *class abc *{ * static int a=10; * static int b; * // static variables * * static void printAll(int n) * { * System.out.println("N = "+n); * System.out.println("A = "+a); * System.out.println("B = "+b); * } * static * { * System.out.println("Static block executed"); * b=a*2; * } *}
  • 7. *class demo *{ * public static void main(String args[]) * { * // static methods are directly called without object * * printAll(5); * } *} *Output: N = 5 * A = 10 * Static block executed * B = 20
  • 8. *Example – 2 * class teststatic * { * static int a = 10; * static int b = 20; * // static variables * static void printA() * { * System.out.println("A = "+a); * } * } * class staticinotherclass * { * public static void main(String args[]) * { * // static methods are directly called without object * * teststatic.printA(); * System.out.println("B from other class = "+teststatic.b); * } * } * Output: A = 10 * B from other class = 20
  • 9. * *Sometime we may wish to use superclass constructor as they were implemented or we may wish to refer super class variable into subclass where variables with the same name as in superclass exists then java provides a keyword super to solve above difficulties. *You may use super keyword for To call superclass constructor into a subclass To refer superclass variable
  • 10. * Example: To call superclass constructor into a subclass * class box * { * int width,height,depth; * // used when no parameter given * box() * { * width=height=depth=10; * } * box(int a) * { * width=height=depth=a; * } * box(int w, int h, int d) * { * width=w; * height=h; * depth=d; * } * int volumeofbox * { * return(width*depth*height); * } * }
  • 11. *class boxprise extends box *{ * int prise; * boxprise(int w, int h, int d, int p) * { * super(w,h,d); * prise = p; * } *}
  • 12. *class demo *{ * public static void main(String args[]) * { * box b1 = new box(); * System.out.println("Box1 volume is = "+(b1.volumeofbox)); * box b2 = new box(20); * System.out.println("Box2 volume is = "+(b2.volumeofbox)); * boxprise b3 = new boxprise(3,4,5,600); * System.out.println("Price of box is = "+(b3.priseofbox)); * System.out.println("Box3 volume is = "+(b3.volumeofbox)); * } * *} *Output: Box1 volume is = 1000 Box2 volume is = 6000 Price of box is = 600 Box3 volume is = 60 *When we use super to call superclass constructor then super(); must be in the first line of subclass.
  • 13. * Example: To refer superclass variable * class A * { * int a; * } * class B extends A * { * int a; int b; * B(int x, int y, int z) * { * super.a=x; * // assigns value to a variable of super class * a=y; * b=z; * } * void displayAll() * { * System.out.println("super.a =", +super.a ); * // access variable of super class in sub class * System.out.println("A = ",+a); * System.out.println("B = ",+b); * } * }
  • 14. * class demo * { * public static void main(String args[]) * { * B b1 = new B(10,20,30); * b1.displayAll(); * } * } * Output: super.a = 10 * A = 20 * B = 30
  • 15. * To declared as constant *Whenever you want to declare any variable whose value cannot be changed at any time then you can do this by declaring that variable as final. *Using final you can define constant in java program *Syntax = final datatype variablename = value; *Example = final float PI = 3.14; *Generally variable declared as final which are written in uppercase.
  • 16. *To prevent method overriding * Write the final precede the method than it cannot be overridden. * Method declared as final cannot be declared as an abstract method because it cannot be overridden. *Example: * class xyz * { * final void printmessage() * { * System.out.println("hello"); * } * } * class B extends xyz * { * final void printmessage() * { * // error in the following line because method declared as final cannot be override * System.out.println("hello"); * } * } *
  • 17. *To prevent inheritance *To do this write final precede the class declaration than it cannot be inherited. *Declaring class as final, indirectly declared all of its method as final too. *It is illegal to declare a class as both abstract and final. *Example: *final class A *{ *} *class B extends A // illegal *{ *} *A final class must full defined its methods with complete definition because they are directly final and final method cannot be redefine.