logo

  • Hỏi Đáp
  • Kiến Thức
  • Sức Khỏe
  • Tử Vi
  • Công Nghệ
No Result
View All Result
logo
No Result
View All Result
Trang chủ classes and objects

Classes And Objects

by Admin _ June 28, 2022
PHP is a server-side scripting language, mainly used for web development but also used as a general-purpose programming language. Object-Oriented Programming (PHP OOP), is a type of programming language principle added to php5, that helps in building complex, reusable web applications.

Bạn đang xem: Classes and objects


*

Example for Single Level Inheritance 

OutputHi : PavanI am from darkedeneurope.comHi: savanI am from ABC

MultiLevel Inheritance : In MultiLevel Inheritance, the parent class method will be inherited by child class and again subclass will inherit the child class method. 

*

 

Output

Class A is 80Class B is 50 Class C 20

 

INTERFACES:

An interface is a description of the actions that an object can do.Interface is written in the same way as the class the declaration with interface keyword.

Rules of Interfaces:

All methods declared in an interface must be public; this is the nature of an interface.All methods in the interface must be implemented within a class; failure to do so will result in a fatal error.The class implementing the interface must use the exact same method signatures as are defined in the interfaceInterfaces can be extended like classes using the extends operator.

Example for the interface class

Output:Describing Mango tree

2) Interface can be extended with another interface using extends keyword

 

Output:division of 10/2 is 5multiplication of 2*3 is 6

Note on Interfaces:-

We cannot create objects to interface, but the class implementing the interface can have objectsWe cannot define a variable in an interface.If we extend interface all the methods of the interface must be implemented in the child class.

 

Abstract Classes:

An abstract class is a class that contains at least one abstract method. The abstract method is function declaration without anybody and it has the only name of the method and its parameters.There can be any number of methods in the class and we have to declare the class as abstract only when there is an abstract method

Example for Abstract class

Output for the above code is:Maruthi Suzuki720000Hyundai300000

Notes on Abstract classes:

Objects cannot be created for the abstract classes.If a class has only one method as abstract, then that class must be an abstract class.The child class which extends an abstract class must define all the methods of the abstract class.If the abstract method is defined as protected in the parent class, the function implementation must be defined as either protected or public, but not private.The signatures of the methods must match, optional parameter given in the child class will not be accepted and error will be shown.Abstract classes that declare all their methods as abstract are not interfaces with different names. One can implement multiple interfaces, but not extend multiple classes (or abstract classes).

Xem thêm: Sự Thật Về Ung Thư Về Tim Ít Bao Giờ Được Nghe Thấy? Ung Thư Tim Là Gì

Now Let us see the difference between abstract class and interface.

Abstract classInterface

It can have constants, members, method stubs (methods without a body), methods

It can only have constants and methods stubs.

Methods and members can have public or protected visibility

 

Methods of interface should only be public not any other visibility

The concept of multiple inheritances not supported.

 

An interface can extend or a class can implement multiple other interfaces. 

Child class must implement all the abstract method of parent class when extend keyword is used.

 

No need of implementing methods from parent interface when interface is extending another interface

 

In the end, now we are able to create a class, define objects for the class and create methods. We also learned about different topics of object-oriented like inheritance, interface, abstraction. The basic concepts of OOP is explained in this blog. 

ShareTweet Linkedin Pinterest
Previous Post

Php array check if all values are unique code example

Next Post

String concatenation in php

CÙNG CHUYÊN MỤC

form register php

Form register php

09/04/2021
fantastic blog (cms) in php with source code

Fantastic blog (cms) in php with source code

28/04/2021
validate form php javascript

Validate form php javascript

28/04/2021
http diendanlequydon com viewtopic php style 6

Http diendanlequydon com viewtopic php style 6

28/04/2021
php

Php

16/08/2022
how to parse json in php

How to parse json in php

16/08/2022
hướng dẫn cách chạy file php trên xampp chi tiết nhất

Hướng dẫn cách chạy file php trên xampp chi tiết nhất

16/08/2022
zend java bridge

Zend java bridge

16/08/2022

Newsletter

The most important automotive news and events of the day

We won't spam you. Pinky swear.

Chuyên Mục

  • Hỏi Đáp
  • Kiến Thức
  • Sức Khỏe
  • Tử Vi
  • Công Nghệ

News Post

  • Nhận giữ trẻ 6 tháng tuổi

About

Chúng tôi tạo ra trang web nhằm mục đích mang lại kiến thức bổ ích cho cộng đồng, các bài viết được sưu tầm từ nhiều nguồn trên internet giúp mang lại kiến thức khách quan dành cho bạn

©2022 darkedeneurope.com - Website WordPress vì mục đích cộng đồng

Liên Hệ - Giới Thiệu - Nội Quy - Bảo Mật

No Result
View All Result
  • Trang chủ
  • Chuyên mục
    • Hỏi Đáp
    • Kiến Thức
    • Sức Khỏe
    • Tử Vi
    • Công Nghệ
  • Lưu trữ
  • Liên hệ

© 2022 darkedeneurope.com - Website WordPress vì mục đích cộng đồng.