SlideShare a Scribd company logo
STATIC METHODS AND
ABSTRACT CLASSES
PREPARED BY
V.SANTHI
ASSISTANT PROFESSOR,
DEPARTMENT OF COMPUTER APPLICATIONS,
THANJAVUR
STATIC METHODS:
THE STATIC KEYWORD IS USED TO DECLARE PROPERTIES AND METHODS OF A CLASS AS STATIC.
STATIC PROPERTIES AND METHODS CAN BE USED WITHOUT CREATING AN INSTANCE OF THE
CLASS. THE STATIC KEYWORD IS ALSO USED TO DECLARE VARIABLES IN A FUNCTION WHICH KEEP
THEIR VALUE AFTER THE FUNCTION HAS ENDED.
PHP- STATIC METHODS:
• STATIC METHODS CAN BE CALLED DIRECTLY - WITHOUT CREATING AN
INSTANCE OF THE CLASS FIRST.
• STATIC METHODS ARE DECLARED WITH THE STATIC KEYWORD:
SYNTAX:
• <?PHP
CLASS CLASSNAME {
PUBLIC STATIC FUNCTION STATICMETHOD() {
ECHO "HELLO WORLD!";
}
}
?>
EXAMPLE:
• <?PHP
CLASS GREETING {
PUBLIC STATIC FUNCTION WELCOME() {
ECHO "HELLO WORLD!";
}
}
// CALL STATIC METHOD
GREETING::WELCOME();
?>
OUTPUT:
• HELLO WORLD!
• EXAMPLE EXPLAINED
• HERE, WE DECLARE A STATIC METHOD: WELCOME(). THEN, WE CALL THE STATIC METHOD BY USING THE
CLASS NAME, DOUBLE COLON (:, AND THE METHOD NAME (WITHOUT CREATING AN INSTANCE OF THE
CLASS FIRST).
ABSTRACT CLASSES IN PHP:
• ABSTRACT CLASSES AND METHODS ARE WHEN THE PARENT CLASS HAS A
NAMED METHOD, BUT NEED ITS CHILD CLASS(ES) TO FILL OUT THE TASKS.
• AN ABSTRACT CLASS IS A CLASS THAT CONTAINS AT LEAST ONE ABSTRACT
METHOD. AN ABSTRACT METHOD IS A METHOD THAT IS DECLARED, BUT
NOT IMPLEMENTED IN THE CODE.
SYNTAX:
• <?PHP
ABSTRACT CLASS PARENTCLASS {
ABSTRACT PUBLIC FUNCTION SOMEMETHOD1();
ABSTRACT PUBLIC FUNCTION SOMEMETHOD2($NAME, $COLOR);
ABSTRACT PUBLIC FUNCTION SOMEMETHOD3() : STRING;
}
?>
EXAMPLE:
• <?PHP
// PARENT CLASS
ABSTRACT CLASS CAR {
PUBLIC $NAME;
PUBLIC FUNCTION __CONSTRUCT($NAME) {
$THIS->NAME = $NAME;
}
ABSTRACT PUBLIC FUNCTION INTRO() : STRING;
}
// CHILD CLASSES
CLASS AUDI EXTENDS CAR {
PUBLIC FUNCTION INTRO() : STRING {
RETURN “CHOOSE GERMAN QUALITY! I’M AN $THIS->NAME!”;
}
}
CLASS VOLVO EXTENDS CAR {
PUBLIC FUNCTION INTRO() : STRING {
RETURN “PROUD TO BE SWEDISH! I’M A $THIS->NAME!”;
}
}
CLASS CITROEN EXTENDS CAR {
PUBLIC FUNCTION INTRO() : STRING {
RETURN "FRENCH EXTRAVAGANCE! I'M A $THIS->NAME!";
}
}
// CREATE OBJECTS FROM THE CHILD CLASSES
$AUDI = NEW AUDI
ECHO $AUDI->INTRO();
ECHO "<BR>";
$VOLVO = NEW VOLVO("VOLVO");
ECHO $VOLVO->INTRO();
ECHO "<BR>";
$CITROEN = NEW CITROEN("CITROEN");
ECHO $CITROEN->INTRO();
?>
RESULT:
• CHOOSE GERMAN QUALITY! I'M AN AUDI!
PROUD TO BE SWEDISH! I'M A VOLVO!
FRENCH EXTRAVAGANCE! I'M A CITROEN!

More Related Content

Similar to static methods.pptx

Inheritance
InheritanceInheritance
Inheritance
abhay singh
 
php.pdf
php.pdfphp.pdf
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
Complete list of all sap abap keywords
Complete list of all sap abap keywordsComplete list of all sap abap keywords
Complete list of all sap abap keywords
Prakash Thirumoorthy
 
OOP is more than Cars and Dogs
OOP is more than Cars and Dogs OOP is more than Cars and Dogs
OOP is more than Cars and Dogs
Chris Tankersley
 
MDE in Practice
MDE in PracticeMDE in Practice
MDE in Practice
Abdalmassih Yakeen
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
webhostingguy
 
Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,
Ahmad55ali
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3
Mahmoud Ouf
 
Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1
bharath yelugula
 
12.2 Abstract class and Interface.ppt
12.2 Abstract class and Interface.ppt12.2 Abstract class and Interface.ppt
12.2 Abstract class and Interface.ppt
VISHNUSHANKARSINGH3
 
Abap course chapter 7 abap objects and bsp
Abap course   chapter 7 abap objects and bspAbap course   chapter 7 abap objects and bsp
Abap course chapter 7 abap objects and bsp
Milind Patil
 
Explain the explain_plan
Explain the explain_planExplain the explain_plan
Explain the explain_plan
Maria Colgan
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
Vigneshkumar Ponnusamy
 
ABSTRACT CLASSES AND INTERFACES.ppt
ABSTRACT CLASSES AND INTERFACES.pptABSTRACT CLASSES AND INTERFACES.ppt
ABSTRACT CLASSES AND INTERFACES.ppt
JayanthiM15
 
Choose any multi-national organization that you would like to use .docx
Choose any multi-national organization that you would like to use .docxChoose any multi-national organization that you would like to use .docx
Choose any multi-national organization that you would like to use .docx
christinemaritza
 
Analysis of software systems using jQAssistant and Neo4j
Analysis of software systems using jQAssistant and Neo4jAnalysis of software systems using jQAssistant and Neo4j
Analysis of software systems using jQAssistant and Neo4j
Java Usergroup Berlin-Brandenburg
 
MOUG17: How to Build Multi-Client APEX Applications
MOUG17: How to Build Multi-Client APEX ApplicationsMOUG17: How to Build Multi-Client APEX Applications
MOUG17: How to Build Multi-Client APEX Applications
Monica Li
 
Php
PhpPhp
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
jsmith92
 

Similar to static methods.pptx (20)

Inheritance
InheritanceInheritance
Inheritance
 
php.pdf
php.pdfphp.pdf
php.pdf
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
 
Complete list of all sap abap keywords
Complete list of all sap abap keywordsComplete list of all sap abap keywords
Complete list of all sap abap keywords
 
OOP is more than Cars and Dogs
OOP is more than Cars and Dogs OOP is more than Cars and Dogs
OOP is more than Cars and Dogs
 
MDE in Practice
MDE in PracticeMDE in Practice
MDE in Practice
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3
 
Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1
 
12.2 Abstract class and Interface.ppt
12.2 Abstract class and Interface.ppt12.2 Abstract class and Interface.ppt
12.2 Abstract class and Interface.ppt
 
Abap course chapter 7 abap objects and bsp
Abap course   chapter 7 abap objects and bspAbap course   chapter 7 abap objects and bsp
Abap course chapter 7 abap objects and bsp
 
Explain the explain_plan
Explain the explain_planExplain the explain_plan
Explain the explain_plan
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
 
ABSTRACT CLASSES AND INTERFACES.ppt
ABSTRACT CLASSES AND INTERFACES.pptABSTRACT CLASSES AND INTERFACES.ppt
ABSTRACT CLASSES AND INTERFACES.ppt
 
Choose any multi-national organization that you would like to use .docx
Choose any multi-national organization that you would like to use .docxChoose any multi-national organization that you would like to use .docx
Choose any multi-national organization that you would like to use .docx
 
Analysis of software systems using jQAssistant and Neo4j
Analysis of software systems using jQAssistant and Neo4jAnalysis of software systems using jQAssistant and Neo4j
Analysis of software systems using jQAssistant and Neo4j
 
MOUG17: How to Build Multi-Client APEX Applications
MOUG17: How to Build Multi-Client APEX ApplicationsMOUG17: How to Build Multi-Client APEX Applications
MOUG17: How to Build Multi-Client APEX Applications
 
Php
PhpPhp
Php
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 

More from SanthiNivas

Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
SanthiNivas
 
Implementing AJAX in PHP. Asynchronous JavaScript and XML
Implementing AJAX in PHP. Asynchronous JavaScript and XMLImplementing AJAX in PHP. Asynchronous JavaScript and XML
Implementing AJAX in PHP. Asynchronous JavaScript and XML
SanthiNivas
 
packages.ppt
packages.pptpackages.ppt
packages.ppt
SanthiNivas
 
exception-handling-in-java.ppt
exception-handling-in-java.pptexception-handling-in-java.ppt
exception-handling-in-java.ppt
SanthiNivas
 
Introduction to PHP.ppt
Introduction to PHP.pptIntroduction to PHP.ppt
Introduction to PHP.ppt
SanthiNivas
 
Topologies.ppt
Topologies.pptTopologies.ppt
Topologies.ppt
SanthiNivas
 
transmission media.ppt
transmission media.ppttransmission media.ppt
transmission media.ppt
SanthiNivas
 
Internet Basics Presentation.pptx
Internet Basics Presentation.pptxInternet Basics Presentation.pptx
Internet Basics Presentation.pptx
SanthiNivas
 
Topologies.ppt
Topologies.pptTopologies.ppt
Topologies.ppt
SanthiNivas
 
Features of Java.pptx
Features of Java.pptxFeatures of Java.pptx
Features of Java.pptx
SanthiNivas
 
Output Devices.pptx
Output Devices.pptxOutput Devices.pptx
Output Devices.pptx
SanthiNivas
 
Input Devices.pptx
Input Devices.pptxInput Devices.pptx
Input Devices.pptx
SanthiNivas
 
Operating System File Management Unit v.pptx
Operating System File Management Unit v.pptxOperating System File Management Unit v.pptx
Operating System File Management Unit v.pptx
SanthiNivas
 
Input and Output Devices
Input and Output DevicesInput and Output Devices
Input and Output Devices
SanthiNivas
 
HTML
HTMLHTML
DDA ALGORITHM.pdf
DDA ALGORITHM.pdfDDA ALGORITHM.pdf
DDA ALGORITHM.pdf
SanthiNivas
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
SanthiNivas
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
SanthiNivas
 
Page Layout and Background
Page Layout and BackgroundPage Layout and Background
Page Layout and Background
SanthiNivas
 
3-D Transformation in Computer Graphics
3-D Transformation in Computer Graphics3-D Transformation in Computer Graphics
3-D Transformation in Computer Graphics
SanthiNivas
 

More from SanthiNivas (20)

Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
 
Implementing AJAX in PHP. Asynchronous JavaScript and XML
Implementing AJAX in PHP. Asynchronous JavaScript and XMLImplementing AJAX in PHP. Asynchronous JavaScript and XML
Implementing AJAX in PHP. Asynchronous JavaScript and XML
 
packages.ppt
packages.pptpackages.ppt
packages.ppt
 
exception-handling-in-java.ppt
exception-handling-in-java.pptexception-handling-in-java.ppt
exception-handling-in-java.ppt
 
Introduction to PHP.ppt
Introduction to PHP.pptIntroduction to PHP.ppt
Introduction to PHP.ppt
 
Topologies.ppt
Topologies.pptTopologies.ppt
Topologies.ppt
 
transmission media.ppt
transmission media.ppttransmission media.ppt
transmission media.ppt
 
Internet Basics Presentation.pptx
Internet Basics Presentation.pptxInternet Basics Presentation.pptx
Internet Basics Presentation.pptx
 
Topologies.ppt
Topologies.pptTopologies.ppt
Topologies.ppt
 
Features of Java.pptx
Features of Java.pptxFeatures of Java.pptx
Features of Java.pptx
 
Output Devices.pptx
Output Devices.pptxOutput Devices.pptx
Output Devices.pptx
 
Input Devices.pptx
Input Devices.pptxInput Devices.pptx
Input Devices.pptx
 
Operating System File Management Unit v.pptx
Operating System File Management Unit v.pptxOperating System File Management Unit v.pptx
Operating System File Management Unit v.pptx
 
Input and Output Devices
Input and Output DevicesInput and Output Devices
Input and Output Devices
 
HTML
HTMLHTML
HTML
 
DDA ALGORITHM.pdf
DDA ALGORITHM.pdfDDA ALGORITHM.pdf
DDA ALGORITHM.pdf
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
Page Layout and Background
Page Layout and BackgroundPage Layout and Background
Page Layout and Background
 
3-D Transformation in Computer Graphics
3-D Transformation in Computer Graphics3-D Transformation in Computer Graphics
3-D Transformation in Computer Graphics
 

Recently uploaded

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 

Recently uploaded (20)

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 

static methods.pptx

  • 1. STATIC METHODS AND ABSTRACT CLASSES PREPARED BY V.SANTHI ASSISTANT PROFESSOR, DEPARTMENT OF COMPUTER APPLICATIONS, THANJAVUR
  • 2. STATIC METHODS: THE STATIC KEYWORD IS USED TO DECLARE PROPERTIES AND METHODS OF A CLASS AS STATIC. STATIC PROPERTIES AND METHODS CAN BE USED WITHOUT CREATING AN INSTANCE OF THE CLASS. THE STATIC KEYWORD IS ALSO USED TO DECLARE VARIABLES IN A FUNCTION WHICH KEEP THEIR VALUE AFTER THE FUNCTION HAS ENDED.
  • 3. PHP- STATIC METHODS: • STATIC METHODS CAN BE CALLED DIRECTLY - WITHOUT CREATING AN INSTANCE OF THE CLASS FIRST. • STATIC METHODS ARE DECLARED WITH THE STATIC KEYWORD:
  • 4. SYNTAX: • <?PHP CLASS CLASSNAME { PUBLIC STATIC FUNCTION STATICMETHOD() { ECHO "HELLO WORLD!"; } } ?>
  • 5. EXAMPLE: • <?PHP CLASS GREETING { PUBLIC STATIC FUNCTION WELCOME() { ECHO "HELLO WORLD!"; } } // CALL STATIC METHOD GREETING::WELCOME(); ?>
  • 6. OUTPUT: • HELLO WORLD! • EXAMPLE EXPLAINED • HERE, WE DECLARE A STATIC METHOD: WELCOME(). THEN, WE CALL THE STATIC METHOD BY USING THE CLASS NAME, DOUBLE COLON (:, AND THE METHOD NAME (WITHOUT CREATING AN INSTANCE OF THE CLASS FIRST).
  • 7. ABSTRACT CLASSES IN PHP: • ABSTRACT CLASSES AND METHODS ARE WHEN THE PARENT CLASS HAS A NAMED METHOD, BUT NEED ITS CHILD CLASS(ES) TO FILL OUT THE TASKS. • AN ABSTRACT CLASS IS A CLASS THAT CONTAINS AT LEAST ONE ABSTRACT METHOD. AN ABSTRACT METHOD IS A METHOD THAT IS DECLARED, BUT NOT IMPLEMENTED IN THE CODE.
  • 8. SYNTAX: • <?PHP ABSTRACT CLASS PARENTCLASS { ABSTRACT PUBLIC FUNCTION SOMEMETHOD1(); ABSTRACT PUBLIC FUNCTION SOMEMETHOD2($NAME, $COLOR); ABSTRACT PUBLIC FUNCTION SOMEMETHOD3() : STRING; } ?>
  • 9. EXAMPLE: • <?PHP // PARENT CLASS ABSTRACT CLASS CAR { PUBLIC $NAME; PUBLIC FUNCTION __CONSTRUCT($NAME) { $THIS->NAME = $NAME; } ABSTRACT PUBLIC FUNCTION INTRO() : STRING; }
  • 10. // CHILD CLASSES CLASS AUDI EXTENDS CAR { PUBLIC FUNCTION INTRO() : STRING { RETURN “CHOOSE GERMAN QUALITY! I’M AN $THIS->NAME!”; } } CLASS VOLVO EXTENDS CAR { PUBLIC FUNCTION INTRO() : STRING { RETURN “PROUD TO BE SWEDISH! I’M A $THIS->NAME!”; } }
  • 11. CLASS CITROEN EXTENDS CAR { PUBLIC FUNCTION INTRO() : STRING { RETURN "FRENCH EXTRAVAGANCE! I'M A $THIS->NAME!"; } } // CREATE OBJECTS FROM THE CHILD CLASSES $AUDI = NEW AUDI
  • 12. ECHO $AUDI->INTRO(); ECHO "<BR>"; $VOLVO = NEW VOLVO("VOLVO"); ECHO $VOLVO->INTRO(); ECHO "<BR>"; $CITROEN = NEW CITROEN("CITROEN"); ECHO $CITROEN->INTRO(); ?>
  • 13. RESULT: • CHOOSE GERMAN QUALITY! I'M AN AUDI! PROUD TO BE SWEDISH! I'M A VOLVO! FRENCH EXTRAVAGANCE! I'M A CITROEN!