SlideShare uma empresa Scribd logo
1 de 18
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

Mais conteúdo relacionado

Mais procurados

Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
Functional programming with clojure
Functional programming with clojureFunctional programming with clojure
Functional programming with clojureLucy Fang
 
Quick python reference
Quick python referenceQuick python reference
Quick python referenceJayant Parida
 
Interface
InterfaceInterface
Interfacevvpadhu
 
Lecture - 5 Control Statement
Lecture - 5 Control StatementLecture - 5 Control Statement
Lecture - 5 Control Statementmanish kumar
 
Generics in .NET, C++ and Java
Generics in .NET, C++ and JavaGenerics in .NET, C++ and Java
Generics in .NET, C++ and JavaSasha Goldshtein
 
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 196Mahmoud Samir Fayed
 
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. TrinidadLUISITO 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 examplePavan b
 

Mais procurados (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
 

Destaque

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-flowMohammed 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 KhanhDevDay.org
 
Becoming a Better Developer #WCA2
Becoming a Better Developer #WCA2Becoming a Better Developer #WCA2
Becoming a Better Developer #WCA2Brian 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 nexusUnit Nexus Pvt. Ltd.
 

Destaque (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
 

Semelhante a Keywords of java

Semelhante a 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
 

Último

College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Último (20)

College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

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.