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

What is the fee for php classess?
Basic + Advanced + WD + MVC, full php developer profile Rs. 12000/- 4 month with practice.
Manjunath
how to place freshers job opening here?
Hello Rajesh, As an PHP aspirant you should be able to handle Basic HTML and CSS with hands on Javascript like putting together PHP and JS, Good expertise of Jquery like handling all DOM manipulations,...
Rajesh
Looking for Yii Framework experts who are willing to train.
A constructor is a special method of a class in object-oriented programming that initializes an object of that type. A constructor will have same name as the class, and can be used to set the values...
Pritam
What are global variable in php ?
A variable declared outside a function is global
Ajay

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

Ask a Question

Related Lessons

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...

How to create your website with PHP?
PHP is a server-side programming language used to create web pages that are more interactive than their HTML counterparts. PHP also optimizes the speed of web pages since processing occurs on the server...

Components of Digital Marketing
Content marketing Search Engine Optimization (SEO) Paid Search (PPC) Email marketing Social Media Marketing Digital Display Marketing (Ad Ops) Web Analytics and Reporting Mobile Marketing 30...

What is M.S.Project ?
MICROSOFT PROJECT contains project work and project groups, schedules and finances.Microsoft Project permits its users to line realistic goals for project groups and customers by making schedules, distributing...

User Authenication In PHP: Some Advanced echniques
User Authentication in CodeIgniter: Goals Security: We want our login system to be secure, we want to do everything we can to stop people’s accounts being hacked into. Tracking: We’d like...

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