1. What is abstract class?
Abstract cls contains abstract methods and abstract data members, abstract methods are methods with out definition. Abstract class can also contain non
abstract methods ie., method with definition. We cannot create object for abstract cls. Abstract cls are inherited by derived classes and they should
implement all the abstract methods of the inherited abstract class.
2. Why we cant create object for abstract class?
To create an object of any class its mandatory to know that how much memory required to load the class so in case of abstract class its can't be calculated
for abstract members thats why we can't create object of abstract class
an abstract class is a partial implementation of a class. In other words, at least some of the operations or methods are implemented, but the full
implementation is left up to an inherited class.
Without a full implementation, how could we instantiate the class? What if the client was to call one of the abstract (not defined) operations? Obviously,
this would result in a failure.
3. What is encapsulation?
Encapsulation is the process of grouping up of datamembers and member functions.
4. Give an example for encapsulation?
Class encapsulates data member and member function. These function and data members are inaccessible to outside environment.
5. Why java does not support multiple inheritances?
1) first reason is ambiguity around diamond problem, consider a class a has foo() method and then b and c derived from a and has there own foo()
implementation and now class d derive from b and c using multiple inheritance and if we refer just foo() compiler will not be able to decide which foo() it
should invoke. This is also called diamond problem because structure on this inheritance scenario is similar to 4 edge diamond, see below
foo() b c foo()
2) multiple inheritances does complicate the design and creates problem during casting, constructor chaining etc
6. When finally block will not be executed?
When try or catch block calls system.exit(), then finally block will not be executed.
If the jvm exits while the try or catch code is being executed, then the finally block may not execute. Likewise, if the thread executing the try or catch
code is interrupted or killed, the finally block may not execute even though the application as a whole continues.
7. Programs: (reverse the string without using inbuilt function)
cout<<"enter the string";
8. Program: (print triangle in following format)
3 6 9
4 8 12 16
5 10 15 20 25
cout<<"enter the limit ie the number of rows";
cin>>n; //here n=5;