UrbanPro

Learn PHP from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

What is abstract class in php?

Asked by Last Modified  

1 Answer

Learn PHP

Follow 1
Answer

Please enter your answer

In PHP, an abstract class is a class that cannot be instantiated on its own and is meant to be subclassed by other classes. Abstract classes can have abstract methods, which are declared but not implemented in the abstract class. Subclasses that extend an abstract class must provide concrete implementations...
read more

In PHP, an abstract class is a class that cannot be instantiated on its own and is meant to be subclassed by other classes. Abstract classes can have abstract methods, which are declared but not implemented in the abstract class. Subclasses that extend an abstract class must provide concrete implementations for all abstract methods.

Here are the key features of abstract classes in PHP:

  1. Cannot be Instantiated:

    • An abstract class cannot be instantiated directly. It serves as a blueprint for other classes.
  2. May Contain Abstract Methods:

    • Abstract classes can declare abstract methods, which are methods without an implementation in the abstract class itself.
  3. May Contain Concrete Methods:

    • Abstract classes can also have regular (concrete) methods with implementations.
  4. Designed for Inheritance:

    • The primary purpose of abstract classes is to be extended by other classes. Subclasses inherit the structure (methods and properties) of the abstract class.
  5. Abstract Methods Must be Implemented:

    • Any class that extends an abstract class must provide concrete implementations for all abstract methods declared in the abstract class.

Here's an example of an abstract class in PHP:

php
abstract class Shape { abstract public function calculateArea(); // Abstract method without implementation public function displayArea() { echo "Area: " . $this->calculateArea() . PHP_EOL; } } class Circle extends Shape { private $radius; public function __construct($radius) { $this->radius = $radius; } public function calculateArea() { return pi() * pow($this->radius, 2); } } // Usage $circle = new Circle(5); $circle->displayArea();

In this example, Shape is an abstract class with an abstract method calculateArea(). The Circle class extends the Shape class and provides a concrete implementation for the calculateArea() method. The displayArea() method in the Shape class uses the abstract calculateArea() method to display the area of the shape.

 
 
 
read less
Comments

Related Questions

PHP (LAMP) for entrepreneurs, is there any full time, fast track classes on PHP(LAMP) for entrepreneurs, who want are want to do some tech part in their startups
Yes, You have option. You can Join. Xpert Infotech, New Delhi. Before going through Silverlight live project training candidate should have knowledge of given concepts listed below: Knowledge of HTML...
Saee
0 0
6
As a fresher I have done Python training, but hardly getting response from any company. What should I do?
only having training in Python is not enough to be called for intervew. Better you should get real time certification course form reputed organisation with smart hand-on real project exposure. Try to have...
Yamini
0 0
6
What is Advanced PHP?
In Advanced PHP, you can learn frameworks of PHP like CakePHP and CodeIgniter.
Geeta
Php-mysql Course Fees?
Rs 5000/- for the entire course
Piyush

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Software Development Training In Jaipur
Satyam Web Solution provides website designing &development and software designing &development training in Jaipur for various stream’s students. MCA 6 month Industrial Training/Internship B....

How to Create A Master Page Template In PHP?
A master page template is essential to give a consistent look and feel to any website having multiple pages. It is quite easy to create a master page template in PHP using Dreamweaver. Let’s have...

Be Carefull While Uploading A file To Server Using PHP
With PHP, it is easy to upload files to the server. However, with ease comes danger, so always be careful when allowing file uploads. 1. Configure The "php.ini" File: First, ensure that PHP is configured...

What Is PHP?
PHP stands for PHP: Hypertext Preprocessor PHP is a widely-used, open source scripting language PHP scripts are executed on the server PHP is free to download and use PHP files can contain text,...

Migration from other languages to Salesforce
Anyone can easily migrate from other language to Salesforce. People must have skills to understand business logic.

Recommended Articles

Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...

Read full article >

Software Development has been one of the most popular career trends since years. The reason behind this is the fact that software are being used almost everywhere today.  In all of our lives, from the morning’s alarm clock to the coffee maker, car, mobile phone, computer, ATM and in almost everything we use in our daily...

Read full article >

Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...

Read full article >

Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...

Read full article >

Looking for PHP Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for PHP Classes?

The best tutors for PHP Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn PHP with the Best Tutors

The best Tutors for PHP Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more