Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Inheritance
Inheritance can be defined as the process where one (parent/super) class acquires
the properties (methods and fields) of another (child/sub). With the use of
inheritance, the information is made manageable in a hierarchical order.
Polymorphism
Abstraction
Abstraction is a process of hiding the implementation details from the user, only
the functionality will be provided to the user. In other words, the user will have
the information on what the object does instead of how it does it.
Encapsulation
Encapsulation in Java is a mechanism for wrapping the data (variables) and code
acting on the data (methods) together as a single unit. In encapsulation, the
variables of a class will be hidden from other classes and can be accessed only
through the methods of their current class. Therefore, it is also known as data
hiding. To achieve encapsulation in Java -
B)
endl
The endl manipulator works the same way as the �\n� character in C++. That is the
endl manipulator outputs the subsequent data or text in the next line.
But the difference is that endl also flushes the output buffer when it is used in a
program.
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int num;
cout<<"Enter your roll number: ";
cin>>num;
In the above program, endl operator is used in the fourth statement inside main()
function.
After this statement, the string �Welcome to your new class!!� is printed in the
next line on the output screen.
setw manipulator
This manipulator is used to set the width of the output in a program. It takes up
an argument �n� which is the width of the field in which the output is to be
displayed.
#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
int main()
{
int num1,num2,num3;
cout<<"Enter three numbers:\n";
cin>>num1>>num2>>num3;
getch();
return 0;
}
In the program above, we ask the user to input three integers and then we display
them using setw() manipulator.
Notice how we have cascaded the �<<� operator to display the three numbers. We
could have used individual cout statements for displaying each number.
Here is a live preview of this program along with its output. We can see how each
of the three numbers is right aligned in a field width of size 8.