xxxxxxxxxx
// Disable
sudo a2dismod php7.2
// Enable
sudo a2enmod php5.3
// Restart Apache
service apache2 restart
// Restart nginx
systemctl restart nginx
xxxxxxxxxx
- "is a" relationship
- All class extends `Object` class
- extended or derived class has same logic as base class (`public` and `protected`)
- Allows code re-use
- `protected` = access modifier that acts like public in a package
- `private` members are not inherited by subclasses / derived class
xxxxxxxxxx
class left {
public:
void foo();
};
class right {
public:
void foo();
};
class bottom : public left, public right {
public:
void foo()
{
//base::foo();// ambiguous
left::foo();
right::foo();
// and when foo() is not called for 'this':
bottom b;
b.left::foo(); // calls b.foo() from 'left'
b.right::foo(); // call b.foo() from 'right'
}
};
xxxxxxxxxx
class Base {
public Base() {
System.out.println("Base");
}
}
class Derived extends Base {
public Derived() {
System.out.println("Derived");
}
}
class DeriDerived extends Derived {
public DeriDerived() {
System.out.println("DeriDerived");
}
}
public class Test {
public static void main(String[] args) {
Derived b = new DeriDerived();
}
}
xxxxxxxxxx
// C++ Implementation to show that a derived class
// doesn’t inherit access to private data members.
// However, it does inherit a full parent object.
class A{
public:
int x;
protected:
int y;
private:
int z;
};
class B : public A{
// x is public
// y is protected
// z is not accessible from B
};
class C : protected A{
// x is protected
// y is protected
// z is not accessible from C
};
class D : private A{ // 'private' is default for classes
// x is private
// y is private
// z is not accessible from D
};
xxxxxxxxxx
class Parent {
// methods
// fields
// ……
}
class Child extends Parent {
// already supports the methods and fields in Parent class
// additional features
}
xxxxxxxxxx
class Print2D
{
public int X { get; set; }
public int Y { get; set; }
public Print2D(int y,int x)
{
X = x;
Y = y;
Console.WriteLine("2D");
}
public void Printing2D()
{
Console.WriteLine("X=\t"+X);
Console.WriteLine("Y=\t"+Y);
}
}
class Print3D:Print2D
{
public int X { get; set; }
public int Y { get; set; }
public int Z { get; set; }
public Print3D(int x,int y,int z) : base(x,y)
{
Z = z;
Console.WriteLine("3D");
}
public void Printing3D()
{
base.Printing2D();
Console.WriteLine("Z=\t" + Z);
}
}
class Program
{
static void Main(string[] args)
{
Print3D p3d = new Print3D(4,5,6);
p3d.Printing3D();
}
}
xxxxxxxxxx
#include <iostream>
using namespace std;
// Base class
class Shape {
public:
void setWidth(int w) {
width = w;
}
void setHeight(int h) {
height = h;
}
protected:
int width;
int height;
};
// Derived class
class Rectangle: public Shape {
public:
int getArea() {
return (width * height);
}
};
int main(void) {
Rectangle Rect;
Rect.setWidth(5);
Rect.setHeight(7);
// Print the area of the object.
cout << "Total area: " << Rect.getArea() << endl;
return 0;
}