Laravel

PHP OOP Essentials

Classes, objects, visibility, inheritance, traits, interfaces, abstract classes, static members

20 pertanyaan wawancaraยท
Junior
1

What is a class in PHP?

Jawaban

A class is a blueprint that defines the properties and methods of an object. It encapsulates data (properties) and behaviors (methods) in a reusable structure. Classes allow creating multiple instances (objects) with the same structure but different values.

2

How to create an instance of a class in PHP?

Jawaban

The 'new' keyword allows instantiating a class and creating an object. For example, 'new User()' creates a new instance of the User class. If the class has a constructor, arguments can be passed directly: 'new User("John")', which automatically calls __construct() with the provided parameters.

3

What is the difference between a 'public' and 'private' property in PHP?

Jawaban

A 'public' property is accessible from outside the class (via the object or in child classes), while a 'private' property is accessible only from the class that defines it. Using 'private' encapsulates data and prevents direct access, forcing the use of getters/setters to control data manipulation. This is a recommended practice to protect data integrity.

4

What is the role of 'protected' visibility in PHP?

5

How to define a constructor in PHP?

+17 pertanyaan wawancara

Kuasai Laravel untuk wawancara berikutnya

Akses semua pertanyaan, flashcards, tes teknis, latihan code review dan simulator wawancara.

Mulai gratis