Beruflich Dokumente
Kultur Dokumente
m mkmI
ne
A coIIection of objects with same
properties and functions is known as
cIass.
As a modeI for creating different
objects of same type
omnrion
n C++ a cIass ends with a simicoIon.
But in JAVA this is not the case.
CIass A{
....
...
};
n C++, there are pubIic and private sections,
started by the keywords pubIic and private.
n Java, each individuaI item must be tagged
with pubIic or private.
nme
class a
prlvaLe lnL number1
publlc lnL number2
prlvaLe vold meLhod1()
0jecl
bject is an entity that consists of data
and functions.
An object has to things:
Properties
Functions
omnrion
hen one object is assigned to another, a
copy of the actuaI vaIues is made.
n Java, copying an object variabIe mereIy
estabIishes a second reference to the
object.
Two object variabIes cannot jointIy access
one object. f you need this effect in C++,
then you need to use pointers.
unclion
A function is a named bIock of code
that perform some action.
Functions are the buiIding bIocks of
C++ programs.
They encapsuIate piece of code to
perform specified operations.
omnrion
n Java, every function must be an instance
method or a static function of a cIass.
n C++ it aIso permits functions that are not a
part of any cIass. Such functions are
caIIed gIobaI functions.
C++ has two parameter passing
mechanisms, caII by vaIue and caII by
reference. n JAVA there is onIy caII by vaIue.
n4erilnnce
A programming technique that is used to
reuse an existing cIass to buiId a new cIass
is known as inheritance.
New cIass inherits aII the behavior of the
originaI cIass.
W Parent cIass
W ChiId cIass
omnrion
n java there is a structure caIIed
interface.
Java does not support muItipIe
inheritance but C++ has this feature.
However more than one "interface"
can be impIemented in java which
amounts to the same thing.
onlruclor nnd :erondinq
A type of member function that is automaticaIIy
executed when an object of that cIass is created is
known as constructor.
There can be muItipIe constructors, with different
numbers or types of arguments.
Constructor overIoading is a technique in which a
cIass can have any number of constructors that
differ in parameter Iists.
The process of defining additionaI meanings is
known as overIoading.
omnrion
ernlor :erondinq
lncludelosLreamh
lncludeconloh
class Pello
publlc
Pello()
couL"ob[ecL creaLed"
omnrion
JAVA:
ExampIes of vaIid constructors for cIass
Account are
Account(int a);
Account (int a,int b);
Account (String a,int b);
ernlor o:erondinq
n JAVA you cannot overIoad
operators, but in C++ you can do that.
void operator ++()
{
function body;
}
eflnlLlon of C
W C ls also known as C sharp
W ln !une 2000 MlcrosofL announced boLh Lhe nL1 plaLform
and a new programmlng language called C
W Ma[or parL of C ls based on C++ and lL conLalns feaLures
slmllar Lo programmlng language !ava
W C ls a sLronglyLyped ob[ecLorlenLed language deslgned Lo
glve Lhe opLlmum blend of slmpllclLy expresslveness
and performance
eflnlLlon of C
W lL was coauLhored by Anders Pe[lsberg (who ls famous for Lhe
deslgn of Lhe elphl language) and ScoLL WllLamuLh
W C uses a synLax somewhaL based on C++
W lL ls an ob[ecL orlenLed language and Lakes parL of lLs CC
model from C++
MeLhod/luncLlon eclaraLlon
W ++
publlc
ConsLrucLor()
vold aMemberluncLlon()
vold aluncLloneclaraLlon()
prlvaLe
vold someCLherluncLlon()
lnL avarlable
MeLhod/luncLlon eclaraLlon
W
prlvaLe avarlable
publlc vold aMemberluncLlon()
publlc vold aluncLloneclaraLlon()
prlvaLe vold someCLherluncLlon()
Class eclaraLlon
W ++
class A_Class
C++ classes end wlLh a "
W lorward declaraLlons are requlred
W amp|e
class A()
class 8(
class A(
Class eclaraLlon
W
class A_Class
W no semlcolon afLer a class declaraLlon ln C
W no forward declaraLlons requlred classes can be arranged aL
wlll
amp|e
class 8(
class A(
lnherlLance
W ++
wlll allow mulLlple lnherlLence eg allows a meLhod Lo be
overrlden many Llmes ln subclasses (derlved classes)
W
supporLs lnherlLence buL noL mulLlpleln oLher words a class
can lnherlL lmplemenLaLlon from one base class only
W when a vlrLual meLhod ls called ln a consLrucLor Lhe meLhod
ln Lhe mosL derlved class ls used
Peader llles and lncludes
W ++
allows header flles and oLher class flles Lo be lncluded uslng
Lhe n|ude keyword
W
no need for header flles and lncludes
SwlLch
W ++
supporLs Lhe swlLch sLaLemenL and fall Lhrough
W
supporLs swlLch sLaLemenL buL does noL supporL fall Lhrough
ln Lhe swlLch sLaLemenL
Access Lo class members/funcLlons
W ++
access Lo class members / funcLlons ls done by Lhe doL
and
class A(
publlc
vold show()
class 8
publlc
vold show()
C ob[
ob[Ashow()
ob[8show()
W
access Lo class members / funcLlons ls done only by Lhe doL
(no more or )
olnLers
W ++
W offers polnLers
W
W only offers polnLers ln unsafe mode
Language
W C++ ls a language LhaL runs on all sorLs of plaLforms belng
exLremely popular on unlx and unlxllke sysLems C whlle
sLandardlzed ls rarely seen ouLslde Wlndows
W 1hls means LhaL C++ ls very powerful and exLendable buL C
ls almosL cerLalnly golng Lo be easler Lo learn and use for mosL
purposes
Plerarchy
W C has a common Lype hlerarchy C++ does noL
1PAnk ?Cu