How does Solidity handle inheritance?

In Solidity, inheritance works by allowing contracts to inherit from other contracts. This allows code to be reused, which makes it easier to maintain and build complex applications.

For example, let’s say you have a contract called Parent.sol that contains some basic functions and variables:

contract Parent {
uint public variable1;
function doSomething() public {
// do something
}
}

Now, if you want to create a new contract that inherits from Parent, you can do so by using the “is” keyword:

contract Child is Parent {
// this contract inherits from Parent
function doSomethingElse() public {
// do something else
}
}

In this example, the Child contract will have access to the variable1 and doSomething() functions from the Parent contract. This allows you to reuse code and easily build complex applications.

What is the difference between a category and a class extension?

A category is a way of adding additional methods to an existing class, without having to subclass it. For example, you could add a category to the NSString class to add a method that converts a string to a URL.

A class extension is a way of adding additional private methods and properties to an existing class. For example, you could add a class extension to the UIViewController class to add a private method that handles the loading of view data from a remote server.