What is difference between “class” and “object”?
How to create new class inheriting all functions from a existing class?
- Create a child class
[php]class Child extends Parent {
<definition body>
}[/php] - A child class
- has all the parent class’ member variables
- has all the same parent class’ member functions
- can modify (override) a function inherited from parent class
What is the difference between public, static, private and protected members?
- Public member
- Can be accessed from outside the class
- Can be accessed within the class
- Can be accessed in different class which implements the class declaring that member
- Static member
- Can be accessed like public member but no need to instantiate the class object
- Protected member
- Can be accessed within the class
- Can be accessed from inheriting class (extended class)
- Private member
- Can be accessed within the class only
- Can’t be accessed from inheriting class too (extended class)
What is the difference between interface and class?
- Interface is like a template that prepare all the function names in ahead
- Class can implement an interface and define the function content
- Different classes can define different contents for a same function name
What is difference between abstract class and normal class?
Javascript
How to create an object?
[js]
function labnoObj(ID, value) {
this._ID = ID;
this._value = value;
}
[/js]
How to add/remove an object to an array?
Add object to the end of an array
[js]
var arrObj = [];
var dataObj = new labnoObj(“1”, “value”);
arrObj.push(dataObj);
[/js]
Add object to the beginning of an array
[js]
//…
var dataObj2 = new labnoObj(“1”, “value”);
arrObj.unshift(dataObj2);
[/js]
How to check if an object exists in an array?
[js]
function containsObject(obj, list) {
var i;
for (i = 0; i < list.length; i++) {
if (list[i]._ID == obj._ID) {
return true;
}
}
return false;
}
[/js]
How to use pointer in JS?
[js]
var x = 0;
function a(x)
{
x++;
}
a(x);
alert(x); //Here I want to have 1 instead of 0
[/js]
So, it should be
[js]
var x = {Value: 0};
function a(obj)
{
obj.Value++;
}
a(x);
document.write(x.Value); //Here i want to have 1 instead of 0
[/js]
Leave a Reply