Which one of the following can be used to instantiate an object in php assuming class name to be student?

Which one of the following can be used to instantiate an object in php assuming class name to be student?

Menu
  • H

    Home
  • A

    Aptitude
  • E

    English
  • R

    Reasoning
  • D

    DI
  • G

    GK
  • C

    Current Affairs
  • I

    Interview
  • Computer
    • C

      Computer Fundamentals
    • N

      Networking
    • S

      SQL
    • D

      Database
  • Programming
    • C

      C Program
    • J

      Java Program
    • H

      HTML
    • C

      CSS
    • J

      Javascript
    • P

      PHP Program
  • Engineering
    • C

      Computer Science
    • E

      Electrical Engineering
    • M

      Mechanical Engineering
    • C

      Civil Engineering
    • C

      Chemical Engineering
  • More
    • B

      Banking Awareness
    • C

      Commerce
    • M

      Management
  • A

    Ask Question

  • Home
  • Aptitude
  • English
  • Reasoning
  • DI
  • GK
  • Current Affairs
  • Interview
  • Computer
    • Computer Fundamentals
    • Networking
    • SQL
    • Database
  • Programming
    • C Program
    • Java Program
    • HTML
    • CSS
    • Javascript
    • PHP Program
  • Engineering
    • Computer Science
    • Electrical Engineering
    • Mechanical Engineering
    • Civil Engineering
    • Chemical Engineering
  • More
    • Banking Awareness
    • Commerce
    • Management
  • Ask Question

Which one of the following can be used to instantiate an object in php assuming class name to be student?

Join The Discussion

Related Questions on Object Oriented Concept

This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Basics of Object-Oriented PHP”.

1. The practice of separating the user from the true inner workings of an application through well-known interfaces is known as _________
a) Polymorphism
b) Inheritance
c) Encapsulation
d) Abstraction
View Answer

Answer: c
Explanation: In object-oriented PHP encapsulation is a concept of wrapping up or binding up the data members and methods in a single module.

2. Which of the following term originates from the Greek language that means “having multiple forms,” defines OOP’s ability to redefine, a class’s characteristics?
a) Abstraction
b) Polymorphism
c) Inheritance
d) Differential
View Answer

Answer: b
Explanation: The word polymorphism is derived from Greek word poly which means “many” and morphism which means the property which helps us to assign more than one property.

3. The practice of creating objects based on predefined classes is often referred to as ______________
a) class creation
b) object creation
c) object instantiation
d) class instantiation
View Answer

Answer: d
Explanation: In object-oriented programming, classes are the blueprints of php objects. Classes do not actually become objects until instantiation is done. When someone instantiates a class, it creates an instance of it, thus creating the object. In other words, instantiation is the process of creating an instance of an object in memory.

4. Which one of the following property scopes is not supported by PHP?
a) friendly
b) final
c) public
d) static
View Answer

Answer: a
Explanation: PHP supports five class property scopes: public, private, protected, final and static.

5. Which one of the following can be used to instantiate an object in PHP assuming class name to be Foo?
a) $obj = new $foo;
b) $obj = new foo;
c) $obj = new foo ();
d) obj = new foo ();
View Answer

Answer: c
Explanation: To create a new object in PHP we can use the new statement to instantiate a class.

6. Which one of the following is the right way to define a constant?
a) constant PI = “3.1415”;
b) const $PI = “3.1415”;
c) constant PI = ‘3.1415’;
d) const PI = ‘3.1415’;
View Answer

Answer: d
Explanation: Class constants are created like: const NAME = ‘VALUE’;

7. Which one of the following is the right way to call a class constant, given that the class is mathFunction?
a) echo PI;
b) echo mathFunction->PI;
c) echo mathFunction::PI;
d) echo mathFunction=PI;
View Answer

Answer: c
Explanation: The Scope Resolution Operator “::” is a token that allows access to static, constant, and overridden properties or methods of a class.

8. Which one of the following is the right way to invoke a method?
a) $object->methodName();
b) object->methodName();
c) object::methodName();
d) $object::methodName();
View Answer

Answer: a
Explanation: “->” is a dynamic class method invocation in PHP.

9. Which of the following is/are the right way to declare a method?

i) function functionName() { function body }
ii) scope function functionName() { function body }
iii) method methodName() { method body }
iv) scope method methodName() { method body }

a) Only ii)
b) Only iv)
c) i) and ii)
d) iii) and iv)
View Answer

Answer: c
Explanation: In case of public methods, you can forgo explicitly declaring the scope and just declare the method like you would a function.

10. Which of the following method scopes is/are not supported by PHP?

i) private
ii) friendly
iii) static
iv) abstract

a) Only ii)
b) Only iv)
c) ii) and iv)
d) Only i)
View Answer

Answer: a
Explanation: PHP supports six method scopes: public, private, final, static, protected and abstract. But it does not support friendly.

Sanfoundry Global Education & Learning Series – PHP Programming.

To practice all questions on PHP Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.

Next Steps:

  • Get Free Certificate of Merit in PHP Programming
  • Participate in PHP Programming Certification Contest
  • Become a Top Ranker in PHP Programming
  • Take PHP Programming Tests
  • Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  • Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Which one of the following can be used to instantiate an object in php assuming class name to be student?

Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.

What is instantiate in PHP?

Instantiating an object means that we create a new object of a class in PHP. Before you can create an object, you must create a class. The class is the overall blueprint or template of the object.

Which keyword is used to create an object from a class in PHP?

The new keyword is used to create an object from a class.

Which one of the following is not a way to instantiate a class?

1. Which one of the following class can not be instantiated? Explanation: An abstract class cannot be instantiated.

Which of the following instantiates an object for this class?

Using the new Keyword Java provides the new keyword to instantiate a class. We can also instantiate the above class as follows if we defining a reference variable. We observe that when we use the new keyword followed by the class name, it creates an instance or object of that class.