Friend class is one which has been declared so (as a friend) inside other class to make it access the private members of the class which has extended it's friendship.
For Example,
class A
{
private:
.......
public:
..............
friend class B;
};
class B
{
.......
..............
};
As in the above code snippet, class A has extended it's friendship to class B by declaring B as it's friend inside it's area.
Since the Class B has became a friend of A, B can directly access all the private members of A. But the reverse is not possible.
Where as an abstract class is a one, which doesn't represent any particular object in nature. Instead they use give as abstract look of an object.
For instance,
When we say TATA Indca, Lancer, Ford Icon, Toyota Innova they are different car models. Each of them having their own properties and features, but all of them are Cars. So here, Car is an abstract class where as the others are concrete classes.
Friend Function:A friend function is used for accessing the non-public members of a class. A class can allow non-member functions and other classes to access its own private data, by making them friends. Thus, a friend function is an ordinary function or a member of another class.
Friend Class: A friend class has full access of private data members of another class without being member of that class.
Ex:
Class A
{
Private:
int a, b;
Friend class B;
}
class B
{
//Class B can access the private and protected data members and member's functions of class A.
}
friend class is used to share private data members among different class. For that we are using friend keyword. It doesn't require an object to invoke.
an abstract class is nothing but class which contains both abstract and concrete methods for abstract class we r nt create object Syntax for pure abstract class is abstract class x { public void abstract y(); public void abstract z(); public void abc() { }
Any class which has one or more abstract methods is called an abstract class. But in the normal class we can't have any abstract methods. We cannot create an object for the abstract classes. When we inherit the abstract class we should implement the abstract method which we inherit.
An abstract class cannot have a constructor and hence you cannot invoke the constructor of the class - i.e., you can instantiate an abstract class and hence you cannot call the constructor of an abstract class.
False. In fact, it is possible to have no abstract methods in an abstract class.
A constructor of a class in invoked when a object of that class is created. As an abstract class can't have an object, so we can't create a constructor of the abstract class. But we can create a constructor of a concrete subclass of that abstract class and we have to pass the object of that concrete subclass to the abstract class.
an abstract class is nothing but class which contains both abstract and concrete methods for abstract class we r nt create object Syntax for pure abstract class is abstract class x { public void abstract y(); public void abstract z(); public void abc() { }
Any class which has one or more abstract methods is called an abstract class. But in the normal class we can't have any abstract methods. We cannot create an object for the abstract classes. When we inherit the abstract class we should implement the abstract method which we inherit.
An abstract class cannot have a constructor and hence you cannot invoke the constructor of the class - i.e., you can instantiate an abstract class and hence you cannot call the constructor of an abstract class.
False. In fact, it is possible to have no abstract methods in an abstract class.
The classes which have one or more abstract methods are abstract. To declare a class as abstract, use the abstract keyword in front of the class keyword, before the class declaration. Abstract classes cannot be instantiated. Similarly the new keyword cannot be used to create an object of the abstract class. Remember that the constructors and static variables cannot be declared as abstract. Any subclass of an abstract class must either implement all of the abstract methods in the superclass or be itself declared abstract.
A constructor of a class in invoked when a object of that class is created. As an abstract class can't have an object, so we can't create a constructor of the abstract class. But we can create a constructor of a concrete subclass of that abstract class and we have to pass the object of that concrete subclass to the abstract class.
An abstract class is a class that cannot be directly instantiated. The purpose of such a class is to put some logic in a base class and force derived classes to implement the remaining functionality. Since the full functionality is only available in the derived class, the base class is declared as abstract so that it cannot be instantiated directly.
True - an instance of an abstract class cannot be created. False - derive (subclass) from a class, not the object (the instance).
Unlike abstract class in C++, the abstract class in C# does not have any methods defined as virtual by default. The concept of virtual are not the same between C# and C++, either. Any virtual method must be defined explicitly in C#. Related to abstract methods - interestingly, an abstract class in C# does not have to have any abstract methods. However, the reverse, if a class need to have at least one abstract method, that class must be defined as abstract.
An Abstract class is a special kind of class that cannot be instantiated. It has one or more methods which are not implemented in the class. These methods are declared abstract and they do not contain any code inside them.Ex:abstract class Parent {public abstract String getSon();public abstract String getDaughter();........//More methods that contain specific behaviour/code in them}The above is an abstract class "Parent" that has a lot of functionality but it has declared two abstract methods which have no code inside them. Any class that has one or more abstract methods has to be abstract. This abstract class cannot be instantiated.i.e., the below piece of code will not work. The code will not even compile.Parent object = new Parent();Purpose of Abstract Classes:Abstract classes are generally used where you want an amount of behaviour to be used by the class that extends the abstract class while at the same time giving options to the child class to provide a certain amount of behaviour itself.A Child Class extending the Abstract Class:public class Child extends Parent {public String getSon() {return "Sons Name";}public String getDaughter(){return "Daughters Name";}...... //Code specific to the Child class}
Actually there is no need & most importantly - you cannot create an abstract class without using the abstract keyword
They are very different. An abstract class is a class that represents an abstract concept (Google define "abstract" if you're unsure) such as 'Thoughts' or 'BankAccount'. When a class is defined as abstract it cannot be used (directly) to create an object. Abstract classes are used as super-classes so that all of their subclasses inherit all methods. Interfaces can be thought of as contracts with all of their implementing classes. They simply require all implementing classes to have methods with the same signature as that defined in the interface, but such methods can behave as appropriate. Hope that helps :)