SlideShare a Scribd company logo
2
Most read
3
Most read
This keyword in Java
1. this can be used to refer current class instance variable.
2. this can be used to invoke current class method (implicitly)
3. this() can be used to invoke current class constructor.
4. this can be passed as an argument in the method call.
5. this can be passed as argument in the constructor call.
6. this can be used to return the current class instance from the method.
this keyword in Java.pptx
Java static keyword
1. Variable (also known as a class variable)
2. Method (also known as a class method)
3. Block
4. Nested class
The static keyword belongs to the class than an instance of the class. If it were a non-static
method, JVM creates an object first then call main() method that will lead the problem of
extra memory allocation.
this keyword in Java.pptx
Java static block
1. Is used to initialize the static data member.
2. It is executed before the main method at the time of classloading.
class Example{
static{System.out.println("static block is invoked");}
public static void main(String args[]){
System.out.println("Hello main");
}
}
Java static block rules
1. It executes during class loading
2. It can only use static variables
3. It can not use this
4. It executes only once during the entire execution of the program when the
class loads into the memory
Final Keyword In Java
1. Variable
2. Method
3. Class
Interfaces in Java
In java, an interface is similar to a class, but it contains abstract methods and static final variables only.
🔔 An interface is a container of abstract methods and static final variables.
🔔 An interface, implemented by a class. (class implements interface).
🔔 An interface may extend another interface. (Interface extends Interface).
🔔 An interface never implements another interface, or class.
🔔 A class may implement any number of interfaces.
🔔 We can not instantiate an interface.
🔔 Specifying the keyword abstract for interface methods is optional, it automatically added.
🔔 All the members of an interface are public by default.
interface HumanInterfaceExample {
void learn(String str);
void work();
int duration = 10;
}
Converted code
interface HumanInterfaceExample {
public abstract void learn(String
str);
public abstract void work();
public static final int duration =
10;
}
Difference Between Class and Interface
S.
No.
Class Interface
1. In class, you can instantiate variables and create an object.
In an interface, you can’t instantiate variables and
create an object.
2. Class can contain concrete(with implementation) methods
The interface cannot contain concrete(with
implementation) methods
3.
The access specifiers used with classes are private,
protected, and public.
In Interface only one specifier is used- Public.
Java Abstract Class
An abstract class is a class that created using abstract keyword. In other words, a class prefixed with abstract
keyword is known as an abstract class.
In java, an abstract class may contain abstract methods (methods without implementation) and also non-abstract
methods (methods with implementation).
Syntax
abstract class <ClassName>{
...
}
Java Abstract Class Rules
● An abstract class must be created with abstract keyword.
● An abstract class can be created without any abstract method.
● An abstract class may contain abstract methods and non-abstract methods.
● An abstract class may contain final methods that can not be overridden.
● An abstract class may contain static methods, but the abstract method can not be static.
● An abstract class may have a constructor that gets executed when the child class object
created.
● An abstract method must be overridden by the child class, otherwise, it must be defined as an
abstract class.
● An abstract class can not be instantiated but can be referenced.
Abstract classes vs Interfaces

More Related Content

PPT
Final keyword in java
PPTX
I/O Streams
PPTX
Inner classes in java
PPTX
Java exception handling
PPTX
This keyword in java
PPTX
Control statements in java
PPTX
Type casting in java
Final keyword in java
I/O Streams
Inner classes in java
Java exception handling
This keyword in java
Control statements in java
Type casting in java

What's hot (20)

PPTX
6. static keyword
PPTX
Packages in java
PPT
Exception Handling in JAVA
PPTX
Classes, objects in JAVA
PPT
Java static keyword
PPT
Abstract class in java
PDF
Java variable types
PDF
Arrays in Java
PPTX
Java swing
PPTX
JAVA AWT
PPTX
Abstract class in c++
PPTX
Constructor in java
PPTX
Event Handling in java
PPT
9. Input Output in java
PPTX
Classes objects in java
PPTX
Arrays in Java
PPT
friend function(c++)
PPTX
Static Members-Java.pptx
PPTX
Abstract Class Presentation
PPTX
Constructor and Types of Constructors
6. static keyword
Packages in java
Exception Handling in JAVA
Classes, objects in JAVA
Java static keyword
Abstract class in java
Java variable types
Arrays in Java
Java swing
JAVA AWT
Abstract class in c++
Constructor in java
Event Handling in java
9. Input Output in java
Classes objects in java
Arrays in Java
friend function(c++)
Static Members-Java.pptx
Abstract Class Presentation
Constructor and Types of Constructors
Ad

Similar to this keyword in Java.pptx (20)

PDF
this keyword in Java.pdf
PDF
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
PPTX
Dev labs alliance top 20 basic java interview question for sdet
PPTX
Top 20 basic java interview questions for SDET
PPTX
Dev labs alliance top 20 basic java interview questions for sdet
PPTX
Objects and classes in OO Programming concepts
PDF
1669617800196.pdf
PPTX
This and Static Keyword
DOC
Java interview questions
DOCX
Core java notes with examples
PPTX
Statics in java | Constructors | Exceptions in Java | String in java| class 3
DOCX
Java Core
DOCX
Java Core Parctical
PPT
03_A-OOPs_Interfaces.ppt
DOCX
100 Java questions FOR LOGIC BUILDING SOFTWARE.docx
PDF
Lecture 10
PPTX
25 java interview questions
PDF
Exception handling and packages.pdf
PDF
java-06inheritance
DOCX
Core java questions
this keyword in Java.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
Dev labs alliance top 20 basic java interview question for sdet
Top 20 basic java interview questions for SDET
Dev labs alliance top 20 basic java interview questions for sdet
Objects and classes in OO Programming concepts
1669617800196.pdf
This and Static Keyword
Java interview questions
Core java notes with examples
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Java Core
Java Core Parctical
03_A-OOPs_Interfaces.ppt
100 Java questions FOR LOGIC BUILDING SOFTWARE.docx
Lecture 10
25 java interview questions
Exception handling and packages.pdf
java-06inheritance
Core java questions
Ad

Recently uploaded (20)

PDF
Chad Ayach - A Versatile Aerospace Professional
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
PPTX
Chapter----five---Resource Recovery.pptx
PDF
flutter Launcher Icons, Splash Screens & Fonts
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
PPT
SCOPE_~1- technology of green house and poyhouse
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
TE-AI-Unit VI notes using planning model
PDF
ETO & MEO Certificate of Competency Questions and Answers
PDF
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
PDF
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
PPTX
anatomy of limbus and anterior chamber .pptx
PDF
Top 10 read articles In Managing Information Technology.pdf
PPTX
Simulation of electric circuit laws using tinkercad.pptx
PPTX
Soil science - sampling procedures for soil science lab
PPTX
Ship’s Structural Components.pptx 7.7 Mb
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
Chad Ayach - A Versatile Aerospace Professional
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
Chapter----five---Resource Recovery.pptx
flutter Launcher Icons, Splash Screens & Fonts
Lesson 3_Tessellation.pptx finite Mathematics
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
SCOPE_~1- technology of green house and poyhouse
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Structs to JSON How Go Powers REST APIs.pdf
TE-AI-Unit VI notes using planning model
ETO & MEO Certificate of Competency Questions and Answers
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
anatomy of limbus and anterior chamber .pptx
Top 10 read articles In Managing Information Technology.pdf
Simulation of electric circuit laws using tinkercad.pptx
Soil science - sampling procedures for soil science lab
Ship’s Structural Components.pptx 7.7 Mb
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd

this keyword in Java.pptx

  • 1. This keyword in Java 1. this can be used to refer current class instance variable. 2. this can be used to invoke current class method (implicitly) 3. this() can be used to invoke current class constructor. 4. this can be passed as an argument in the method call. 5. this can be passed as argument in the constructor call. 6. this can be used to return the current class instance from the method.
  • 3. Java static keyword 1. Variable (also known as a class variable) 2. Method (also known as a class method) 3. Block 4. Nested class The static keyword belongs to the class than an instance of the class. If it were a non-static method, JVM creates an object first then call main() method that will lead the problem of extra memory allocation.
  • 5. Java static block 1. Is used to initialize the static data member. 2. It is executed before the main method at the time of classloading. class Example{ static{System.out.println("static block is invoked");} public static void main(String args[]){ System.out.println("Hello main"); } }
  • 6. Java static block rules 1. It executes during class loading 2. It can only use static variables 3. It can not use this 4. It executes only once during the entire execution of the program when the class loads into the memory
  • 7. Final Keyword In Java 1. Variable 2. Method 3. Class
  • 8. Interfaces in Java In java, an interface is similar to a class, but it contains abstract methods and static final variables only. 🔔 An interface is a container of abstract methods and static final variables. 🔔 An interface, implemented by a class. (class implements interface). 🔔 An interface may extend another interface. (Interface extends Interface). 🔔 An interface never implements another interface, or class. 🔔 A class may implement any number of interfaces. 🔔 We can not instantiate an interface. 🔔 Specifying the keyword abstract for interface methods is optional, it automatically added. 🔔 All the members of an interface are public by default.
  • 9. interface HumanInterfaceExample { void learn(String str); void work(); int duration = 10; } Converted code interface HumanInterfaceExample { public abstract void learn(String str); public abstract void work(); public static final int duration = 10; }
  • 10. Difference Between Class and Interface S. No. Class Interface 1. In class, you can instantiate variables and create an object. In an interface, you can’t instantiate variables and create an object. 2. Class can contain concrete(with implementation) methods The interface cannot contain concrete(with implementation) methods 3. The access specifiers used with classes are private, protected, and public. In Interface only one specifier is used- Public.
  • 11. Java Abstract Class An abstract class is a class that created using abstract keyword. In other words, a class prefixed with abstract keyword is known as an abstract class. In java, an abstract class may contain abstract methods (methods without implementation) and also non-abstract methods (methods with implementation). Syntax abstract class <ClassName>{ ... }
  • 12. Java Abstract Class Rules ● An abstract class must be created with abstract keyword. ● An abstract class can be created without any abstract method. ● An abstract class may contain abstract methods and non-abstract methods. ● An abstract class may contain final methods that can not be overridden. ● An abstract class may contain static methods, but the abstract method can not be static. ● An abstract class may have a constructor that gets executed when the child class object created. ● An abstract method must be overridden by the child class, otherwise, it must be defined as an abstract class. ● An abstract class can not be instantiated but can be referenced.
  • 13. Abstract classes vs Interfaces