Declaring class members or methods as static makes them accessible without needing an instantiation of the class. A member declared as static can not be accessed with an instantiated class object (though a static method can).
Showing posts with label oops concept. Show all posts
Showing posts with label oops concept. Show all posts
Tuesday, April 6, 2010
what is abstract class in php
Interview question:
what is abstract class in php
Answer
Abstract classes are not allowed to create instance . We can only inherit the class using some other class.
Labels:
advanced,
inhertitance,
oops concept
what is inheritance in php?
Question:
what is inheritance in php give me an example?
Answer:
Inheritance permits the implementation of additional functionality in similar objects without the need to reimplement all of the shared functionality.
To inherit an another class we have to use extends Keyword
Example:
class phpInterview{
public fuction result(){
echo 'got selected';
}
}
//extending the above class
class questions extends phpInterview{
public function askedQuestions{
echo 'questions mostly from allphpinterviewquestions.blogspot.com ';
}
}
$obj=new questions();
echo $obj-> askedQuestions();
echo $obj->result();
The output is
questions mostly from allphpinterviewquestions.blogspot.com got selected
Labels:
advanced,
inhertitance,
intermediate,
oops concept
How will you check whether a class already defined or not?
Answer
Php has built-in function to check whether a class exists or not
The function is
class_exists()
Labels:
advanced,
intermediate,
oops,
oops concept
Monday, April 5, 2010
How to create objects for a class
Answer
To create an object for a class we need to use the keyword "new"
Example
$phpqna = new Phpinterview();
Now the instance is created and assigned to the variable $phpqna
Also we can create any number of instances to a single class
Example
$phpqna1 = new Phpinterview();
$phpqna2 = new Phpinterview();
Labels:
oops concept
How to create a class in php
Answer
To create a class we need to use a class keyword.
Example
class Phpinterview{
}
}
?>
The above created a class named Phpinterview.
To add a method to a class follow this
class Phpinterview{
function questions{
echo 'php questions';
}
function answers{
echo 'Answers for the questions';
}
}
}
?>
Here you have created two methods questions and answers for the class Phpinterview
Labels:
oops,
oops concept
what is class in php
Answer
Classes are the blue prints for an object.
Classes are the actual code that defined the properties and method
Labels:
advanced,
oops concept
Subscribe to:
Posts (Atom)