SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Java Non Access Modifiers
            SCJP/OCJP exam objectives – 1.1,1.3,1.4




                                              By,
                                       Srinivas Reddy.S
www.JAVA9S.com
Non Access Modifiers
   •   final
   •   static
   •   abstract
   •   strictfp
   •   native
   •   synchronized
   •   transient
   •   volatile
www.JAVA9S.com
final
   • final can be applied for classes, methods,
     instance variables, local variables.
   • A class marked as final cannot be extended.
   • A method marked with final cannot be
     overridden.
   • A primitive data type or an object reference
     will not change its value or object when
     marked final.

www.JAVA9S.com
static
   public class Ford{
     int maxSpeed;
       public Ford(int maxSpeed){                Ford f = new Ford(100);
       this.maxSpeed = maxSpeed;
       }
                                                 Ford a = new Ford(200);
       public void move(){                       Ford e = new Ford(150);
       int speed = 0;
       while(speed<maxSpeed){
               System.out.println(“Racing with speed”+speed);
               speed++;
               }                                                            function
                                                           f.move();
       }                                                                    of method
                                                           a.move();
       public void printCarInfo(){                         e.move();        varies from Object
       System.out.println(“Car name : Ford“);                               to object
       System.out.println(“ Car weight : 230”);
                                                        f.printCarInfo();
       System.out.println(“Engine Capacity: 3000cc”);
                                                        a.printCarInfo();      Same output
       }
                                                        e.printCarInfo();
   }
www.JAVA9S.com
static




                                                            Virtual Memory




         .Class File
                       Members marked as static belong to the Class file and
                       not the instances

www.JAVA9S.com
static
   • static can be applied for methods and
     variables.
   • A method or variable marked as static
     belongs to class file.
   • A static member should be accessed using
     the class name.




www.JAVA9S.com
Accessing static members
   • static members can be accessed using the
     class name.
   E.g.,
     public class Ford{
               public static void printCarInfo(){
               System.out.println(“Car name : Ford“);
               System.out.println(“ Car weight : 230”);
               System.out.println(“Engine Capacity: 3000cc”);
               }
     }



       Ford.printCarInfo();

www.JAVA9S.com
Accessing static members
   public class Ford{
             public static void printCarInfo(){
             System.out.println(“Car name : Ford“);
             System.out.println(“ Car weight : 230”);
             System.out.println(“Engine Capacity: 3000cc”);
             }
   }



   public class FordShowRoom(){
                                                    public class FordShowRoom(){
             public void getCarInfo(){
                                                              public void getCarInfo(){
             Ford f = new Ford();
                                                              Ford.printCarInfo();
             f.printCarInfo();
                                                              }
             }
                                                    }
   }



www.JAVA9S.com
static - rules
   • The static variable and static methods are called
     class members.
   • A method marked as static can only access other
     static methods and variables directly.
   • To access the instance variables and methods, a
     static method should have an instance on which
     the object members should be invoked.
   • Any instance can access the static variables and
     can change them. But, the changes will reflect
     for all the objects.
   • Members marked as static can be final

www.JAVA9S.com
static - example




www.JAVA9S.com
public static void main(String[] args){ }




www.JAVA9S.com
abstract
   public class Car{
     public void move(){
      System.out.println(“Moves at max 40 kmph”);
      }
   }

                     Benz
     Ford
                                               BMW
                                Ferrari


            Toyota




www.JAVA9S.com
abstract
   public abstract class Car{
     public abstract void move();
   }


     public class Ford extends Car{
               public void move(){
               System.out.println(“Move at 120 kmph”);
               }
     }

       public class Benz extends Car{
                 public void move(){
                 System.out.println(“Move at 200 kmph – Comfortably ”);
                 }
       }

www.JAVA9S.com
abstract - rules
   • abstract can be applied for classes and
     methods only.
   • When a method is marked as abstract – It
     should not have implementation.
   E.g., public abstract void move();
   • Abstract methods should end with ‘;’ and not
     with ‘{ }’.


www.JAVA9S.com
abstract - Rules
   • When a method marked as abstract, the
     whole class should be marked as abstract.
   • A class can be abstract with out any abstract
     methods in it.
   • We cannot create an instance of abstract
     class.
   • An abstract method should be overridden in
     the subclass or should be marked as abstract.

www.JAVA9S.com
abstract - rules
   • Abstract classes can have concrete(non-
     abstract) methods in it.
   • Abstract methods cannot be marked as final.
   • Abstract classes cannot be marked as final.
   • Abstract methods cannot be static.
   • Abstract methods cannot be private



www.JAVA9S.com
abstract - rules
   • Cannot create an instance of abstract
     class???
       – An abstract class can contain abstract methods
         which does not have functionality and if we can
         create objects, we do not have functionality in
         abstract methods.
       – So, abstract classes are incomplete and are not
         eligible for creating instances.



www.JAVA9S.com
strictfp
   • strictfp can only be declared for methods and
     classes.
   • When declared, the code inside a class or
     method will conform to IEEE754 standard
     which makes the methods or classes behave
     in a platform independent way regarding the
     floating points.
   • strictfp cannot be used with abstract.

www.JAVA9S.com
native
   • native modifier can only be applied to
     methods.
   • A native method will always have platform
     dependent code like C.
   • A native method should not have the
     implementation and should end with ‘;’.
   • A native methods implementation is
     omitted.

www.JAVA9S.com
synchronized
   • synchronized can only be applied for
     methods.
   • Any method or block that is synchronized will
     only allow one single thread to execute the
     code at a given time.
   • synchronized can be used with any access
     modifier.


www.JAVA9S.com
transient
   • only instance variables can be marked as
     transient.
   • A variable marked as transient will not be
     serialized.
                     volatile
 • volatile can only be applied to instance
   variables


www.JAVA9S.com
Access and non access modifiers -
                classes
   •   public
   •   default
   •   abstract
   •   strictfp
   •   final




www.JAVA9S.com
Access and non access modifiers-
            variables and members
    Methods        Instance variables   Local variables
    public         public               -
    protected      protected            -
    default        default              -
    private        private              -
    static         static               -
    final          final                final
    strictfp       -                    -
    native         -                    -
    -              transient            -
    synchronized   -                    -
    abstract       -                    -

www.JAVA9S.com
Thank you
   Follow me on to get more updates on latest video posts
   Subscribe on

   http://www.youtube.com/user/java9s
   Twitter :   @java9s

   facebook: www.facebook.com/java9s




www.JAVA9S.com

Weitere ähnliche Inhalte

Was ist angesagt?

Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Edureka!
 
Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37myrajendra
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singhdheeraj_cse
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streamsHamid Ghorbani
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Javaparag
 
Java multi threading
Java multi threadingJava multi threading
Java multi threadingRaja Sekhar
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in javayugandhar vadlamudi
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statementsKuppusamy P
 
L21 io streams
L21 io streamsL21 io streams
L21 io streamsteach4uin
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java NotesShalabh Chaudhary
 

Was ist angesagt? (20)

Java threads
Java threadsJava threads
Java threads
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Java awt
Java awtJava awt
Java awt
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
 
Java IO
Java IOJava IO
Java IO
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
 
Java constructors
Java constructorsJava constructors
Java constructors
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 

Andere mochten auch

Brian Mork - DC214 October 2015 - ECB Sucks
Brian Mork - DC214 October 2015 - ECB SucksBrian Mork - DC214 October 2015 - ECB Sucks
Brian Mork - DC214 October 2015 - ECB SucksNothing Nowhere
 
Object-Oriented Programming 4
Object-Oriented Programming 4Object-Oriented Programming 4
Object-Oriented Programming 4Warawut
 
Eo gaddis java_chapter_03_5e
Eo gaddis java_chapter_03_5eEo gaddis java_chapter_03_5e
Eo gaddis java_chapter_03_5eGina Bullock
 
Internship in-chennai-for-it-template-designing
Internship in-chennai-for-it-template-designingInternship in-chennai-for-it-template-designing
Internship in-chennai-for-it-template-designingbhavna_chandar
 
Java se 8 fundamentals
Java se 8 fundamentalsJava se 8 fundamentals
Java se 8 fundamentalsmegharajk
 
Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in javaTech_MX
 
Java access modifiers
Java access modifiersJava access modifiers
Java access modifiersSrinivas Reddy
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and PolymorphismBG Java EE Course
 
Cracking OCA and OCP Java 8 Exams
Cracking OCA and OCP Java 8 ExamsCracking OCA and OCP Java 8 Exams
Cracking OCA and OCP Java 8 ExamsGanesh Samarthyam
 
Sailing with Java 8 Streams
Sailing with Java 8 StreamsSailing with Java 8 Streams
Sailing with Java 8 StreamsGanesh Samarthyam
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
Advance Java
Advance JavaAdvance Java
Advance JavaVidyacenter
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
 
Java Modifiers Matrix
Java Modifiers MatrixJava Modifiers Matrix
Java Modifiers MatrixYasser Ibrahim
 

Andere mochten auch (20)

Brian Mork - DC214 October 2015 - ECB Sucks
Brian Mork - DC214 October 2015 - ECB SucksBrian Mork - DC214 October 2015 - ECB Sucks
Brian Mork - DC214 October 2015 - ECB Sucks
 
Java02
Java02Java02
Java02
 
Object-Oriented Programming 4
Object-Oriented Programming 4Object-Oriented Programming 4
Object-Oriented Programming 4
 
access modifiers
access modifiersaccess modifiers
access modifiers
 
Eo gaddis java_chapter_03_5e
Eo gaddis java_chapter_03_5eEo gaddis java_chapter_03_5e
Eo gaddis java_chapter_03_5e
 
Internship in-chennai-for-it-template-designing
Internship in-chennai-for-it-template-designingInternship in-chennai-for-it-template-designing
Internship in-chennai-for-it-template-designing
 
Lecture 8 Library classes
Lecture 8 Library classesLecture 8 Library classes
Lecture 8 Library classes
 
Java se 8 fundamentals
Java se 8 fundamentalsJava se 8 fundamentals
Java se 8 fundamentals
 
Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in java
 
Java access modifiers
Java access modifiersJava access modifiers
Java access modifiers
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
 
Cracking OCA and OCP Java 8 Exams
Cracking OCA and OCP Java 8 ExamsCracking OCA and OCP Java 8 Exams
Cracking OCA and OCP Java 8 Exams
 
Sailing with Java 8 Streams
Sailing with Java 8 StreamsSailing with Java 8 Streams
Sailing with Java 8 Streams
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Advance Java
Advance JavaAdvance Java
Advance Java
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Java basic
Java basicJava basic
Java basic
 
Java Modifiers Matrix
Java Modifiers MatrixJava Modifiers Matrix
Java Modifiers Matrix
 

Ähnlich wie Java non access modifiers

Java Classes methods and inheritance
Java Classes methods and inheritanceJava Classes methods and inheritance
Java Classes methods and inheritanceSrinivas Reddy
 
OOP with Java - Part 3
OOP with Java - Part 3OOP with Java - Part 3
OOP with Java - Part 3RatnaJava
 
OOP with Java - Part 3
OOP with Java - Part 3OOP with Java - Part 3
OOP with Java - Part 3Hitesh-Java
 
Session 09 - OOP with Java - Part 3
Session 09 - OOP with Java - Part 3Session 09 - OOP with Java - Part 3
Session 09 - OOP with Java - Part 3PawanMM
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application FrameworkJady Yang
 
04 Java Language And OOP Part IV
04 Java Language And OOP Part IV04 Java Language And OOP Part IV
04 Java Language And OOP Part IVHari Christian
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT studentsPartnered Health
 
3java Advanced Oop
3java Advanced Oop3java Advanced Oop
3java Advanced OopAdil Jafri
 
PROGRAMMING IN JAVA- unit 4-part I
PROGRAMMING IN JAVA- unit 4-part IPROGRAMMING IN JAVA- unit 4-part I
PROGRAMMING IN JAVA- unit 4-part ISivaSankari36
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationAjax Experience 2009
 
Java basics notes
Java basics notesJava basics notes
Java basics notesGomathi Gomu
 
New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)jeresig
 
6applets And Graphics
6applets And Graphics6applets And Graphics
6applets And GraphicsAdil Jafri
 
Java basics notes
Java basics notesJava basics notes
Java basics notessanchi Sharma
 
Java basics notes
Java basics notesJava basics notes
Java basics notesNexus
 
java programming - applets
java programming - appletsjava programming - applets
java programming - appletsHarshithaAllu
 
Ratpack Web Framework
Ratpack Web FrameworkRatpack Web Framework
Ratpack Web FrameworkDaniel Woods
 
(5) c sharp introduction_object_orientation_part_ii
(5) c sharp introduction_object_orientation_part_ii(5) c sharp introduction_object_orientation_part_ii
(5) c sharp introduction_object_orientation_part_iiNico Ludwig
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Nayden Gochev
 

Ähnlich wie Java non access modifiers (20)

Java Classes methods and inheritance
Java Classes methods and inheritanceJava Classes methods and inheritance
Java Classes methods and inheritance
 
OOP with Java - Part 3
OOP with Java - Part 3OOP with Java - Part 3
OOP with Java - Part 3
 
OOP with Java - Part 3
OOP with Java - Part 3OOP with Java - Part 3
OOP with Java - Part 3
 
Session 09 - OOP with Java - Part 3
Session 09 - OOP with Java - Part 3Session 09 - OOP with Java - Part 3
Session 09 - OOP with Java - Part 3
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application Framework
 
04 Java Language And OOP Part IV
04 Java Language And OOP Part IV04 Java Language And OOP Part IV
04 Java Language And OOP Part IV
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
 
3java Advanced Oop
3java Advanced Oop3java Advanced Oop
3java Advanced Oop
 
PROGRAMMING IN JAVA- unit 4-part I
PROGRAMMING IN JAVA- unit 4-part IPROGRAMMING IN JAVA- unit 4-part I
PROGRAMMING IN JAVA- unit 4-part I
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)
 
6applets And Graphics
6applets And Graphics6applets And Graphics
6applets And Graphics
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
java programming - applets
java programming - appletsjava programming - applets
java programming - applets
 
Ratpack Web Framework
Ratpack Web FrameworkRatpack Web Framework
Ratpack Web Framework
 
(5) c sharp introduction_object_orientation_part_ii
(5) c sharp introduction_object_orientation_part_ii(5) c sharp introduction_object_orientation_part_ii
(5) c sharp introduction_object_orientation_part_ii
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
 

KĂźrzlich hochgeladen

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 

KĂźrzlich hochgeladen (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

Java non access modifiers

  • 1. Java Non Access Modifiers SCJP/OCJP exam objectives – 1.1,1.3,1.4 By, Srinivas Reddy.S www.JAVA9S.com
  • 2. Non Access Modifiers • final • static • abstract • strictfp • native • synchronized • transient • volatile www.JAVA9S.com
  • 3. final • final can be applied for classes, methods, instance variables, local variables. • A class marked as final cannot be extended. • A method marked with final cannot be overridden. • A primitive data type or an object reference will not change its value or object when marked final. www.JAVA9S.com
  • 4. static public class Ford{ int maxSpeed; public Ford(int maxSpeed){ Ford f = new Ford(100); this.maxSpeed = maxSpeed; } Ford a = new Ford(200); public void move(){ Ford e = new Ford(150); int speed = 0; while(speed<maxSpeed){ System.out.println(“Racing with speed”+speed); speed++; } function f.move(); } of method a.move(); public void printCarInfo(){ e.move(); varies from Object System.out.println(“Car name : Ford“); to object System.out.println(“ Car weight : 230”); f.printCarInfo(); System.out.println(“Engine Capacity: 3000cc”); a.printCarInfo(); Same output } e.printCarInfo(); } www.JAVA9S.com
  • 5. static Virtual Memory .Class File Members marked as static belong to the Class file and not the instances www.JAVA9S.com
  • 6. static • static can be applied for methods and variables. • A method or variable marked as static belongs to class file. • A static member should be accessed using the class name. www.JAVA9S.com
  • 7. Accessing static members • static members can be accessed using the class name. E.g., public class Ford{ public static void printCarInfo(){ System.out.println(“Car name : Ford“); System.out.println(“ Car weight : 230”); System.out.println(“Engine Capacity: 3000cc”); } } Ford.printCarInfo(); www.JAVA9S.com
  • 8. Accessing static members public class Ford{ public static void printCarInfo(){ System.out.println(“Car name : Ford“); System.out.println(“ Car weight : 230”); System.out.println(“Engine Capacity: 3000cc”); } } public class FordShowRoom(){ public class FordShowRoom(){ public void getCarInfo(){ public void getCarInfo(){ Ford f = new Ford(); Ford.printCarInfo(); f.printCarInfo(); } } } } www.JAVA9S.com
  • 9. static - rules • The static variable and static methods are called class members. • A method marked as static can only access other static methods and variables directly. • To access the instance variables and methods, a static method should have an instance on which the object members should be invoked. • Any instance can access the static variables and can change them. But, the changes will reflect for all the objects. • Members marked as static can be final www.JAVA9S.com
  • 11. public static void main(String[] args){ } www.JAVA9S.com
  • 12. abstract public class Car{ public void move(){ System.out.println(“Moves at max 40 kmph”); } } Benz Ford BMW Ferrari Toyota www.JAVA9S.com
  • 13. abstract public abstract class Car{ public abstract void move(); } public class Ford extends Car{ public void move(){ System.out.println(“Move at 120 kmph”); } } public class Benz extends Car{ public void move(){ System.out.println(“Move at 200 kmph – Comfortably ”); } } www.JAVA9S.com
  • 14. abstract - rules • abstract can be applied for classes and methods only. • When a method is marked as abstract – It should not have implementation. E.g., public abstract void move(); • Abstract methods should end with ‘;’ and not with ‘{ }’. www.JAVA9S.com
  • 15. abstract - Rules • When a method marked as abstract, the whole class should be marked as abstract. • A class can be abstract with out any abstract methods in it. • We cannot create an instance of abstract class. • An abstract method should be overridden in the subclass or should be marked as abstract. www.JAVA9S.com
  • 16. abstract - rules • Abstract classes can have concrete(non- abstract) methods in it. • Abstract methods cannot be marked as final. • Abstract classes cannot be marked as final. • Abstract methods cannot be static. • Abstract methods cannot be private www.JAVA9S.com
  • 17. abstract - rules • Cannot create an instance of abstract class??? – An abstract class can contain abstract methods which does not have functionality and if we can create objects, we do not have functionality in abstract methods. – So, abstract classes are incomplete and are not eligible for creating instances. www.JAVA9S.com
  • 18. strictfp • strictfp can only be declared for methods and classes. • When declared, the code inside a class or method will conform to IEEE754 standard which makes the methods or classes behave in a platform independent way regarding the floating points. • strictfp cannot be used with abstract. www.JAVA9S.com
  • 19. native • native modifier can only be applied to methods. • A native method will always have platform dependent code like C. • A native method should not have the implementation and should end with ‘;’. • A native methods implementation is omitted. www.JAVA9S.com
  • 20. synchronized • synchronized can only be applied for methods. • Any method or block that is synchronized will only allow one single thread to execute the code at a given time. • synchronized can be used with any access modifier. www.JAVA9S.com
  • 21. transient • only instance variables can be marked as transient. • A variable marked as transient will not be serialized. volatile • volatile can only be applied to instance variables www.JAVA9S.com
  • 22. Access and non access modifiers - classes • public • default • abstract • strictfp • final www.JAVA9S.com
  • 23. Access and non access modifiers- variables and members Methods Instance variables Local variables public public - protected protected - default default - private private - static static - final final final strictfp - - native - - - transient - synchronized - - abstract - - www.JAVA9S.com
  • 24. Thank you Follow me on to get more updates on latest video posts Subscribe on http://www.youtube.com/user/java9s Twitter : @java9s facebook: www.facebook.com/java9s www.JAVA9S.com