A Brief Introduction of Java
Last Updated on : 3rd Apr 2024 12:43:14 PM
This core java toturial is designed for student and profestional also.we are covering complete core java toturial from begining to advance. java is such a powerful programming language .
What is java ?
Java is a high level object-oriented programming language developed by james gosling in the year 1995 at Sun Microsystems . but now it is leading by Oracle Corporation.
Java is the most used in the world by developers.it is used for web application, system application, mobile application, games, embaded system and enterprise application.
single inharitance in cpp
#include<iostream>
using namespace std;
class student
{
// single inheritance
int roll;
char name[10];
double marks;
public:
void read();
void display();
};
void student::read()
{
cout<<"enter your roll = ";
cin>>roll;
cout<<"enter your name = ";
cin>>name;
cout<<"enter your marks = " ;
cin>>marks;
}
void student::display()
{
cout<<"
your name is "<<name<<"
your roll is = " <<roll<<"
your marks is "<<marks;
}
class stud: public student
{
double mob;
char address[20];
public:
void read1()
{
//read();
cout<<"enter mobile no";
cin>>mob;
cout<<"Enter your Address";
cin>>address;
}
void display1()
{
//display();
cout<<"
your mob is " <<mob;
cout<<"
and address is "<<address;
}
} ;
int main ()
{
stud s;
s.read();
s.read1();
system("cls");
cout<<"____________________";
s.display();
s.display1();
return 0;
}
hiracr
#include <iostream.h>
#include <conio.h>
#include<stdio.h>
class person
{
char name[100],gender[10];
int age; //hierarchical inharitance
public:
void getdata()
{
cout<<"Name: ";
fflush(stdin); /*clears input stream*/
gets(name);
cout<<"Age: ";
cin>>age;
cout<<"Gender: ";
cin>>gender;
}
void display()
{
cout<<"Name: "<<name<<endl;
cout<<"Age: "<<age<<endl;
cout<<"Gender: "<<gender<<endl;
}
};
class student: public person
{
char institute[100], level[20];
public:
void getdata()
{
person::getdata();
cout<<"Name of College/School: ";
fflush(stdin);
gets(institute);
cout<<"Level: ";
cin>>level;
}
void display()
{
person::display();
cout<<"Name of College/School: "<<institute<<endl;
cout<<"Level: "<<level<<endl;
}
};
class employee: public person
{
char company[100];
float salary;
public:
void getdata()
{
person::getdata();
cout<<"Name of Company: ";
fflush(stdin);
gets(company);
cout<<"Salary: Rs.";
cin>>salary;
}
void display()
{
person::display();
cout<<"Name of Company: "<<company<<endl;
cout<<"Salary: Rs."<<salary<<endl;
}
};
int main()
{
clrscr();
student s;
employee e;
cout<<"Student"<<endl;
cout<<"Enter data"<<endl;
s.getdata();
cout<<endl<<"Displaying data"<<endl;
s.display();
cout<<endl<<"Employee"<<endl;
cout<<"Enter data"<<endl;
e.getdata();
cout<<endl<<"Displaying data"<<endl;
e.display();
getch();
return 0;
}
encapsulation
#include <iostream>
using namespace std;
class Student
{ // encapsulation
private:
string name;
int account_number;
public:
Student(string nm, int ac)
{
name=nm;
account_number=ac;
}
string getName()
{
return name;
}
int getAccount()
{
return account_number;
}
};
int main()
{
Student s("aarti",5675) ;
cout<<"My Name is "<<s.getName()<<"Account Number is "<<s.getAccount();
return 0;
}
Become a first user to comment