0% found this document useful (0 votes)
170 views

Oop Assignment 1

The document provides a comparison of object-oriented programming features between Java and C++, including: - Class definition: In C++ classes declare object specifications but don't allocate memory, while in Java classes create objects that behave like instances of that class. - Object creation: In C++ objects exist at runtime, while in Java objects combine data and procedures working on that data. - Abstraction: Both use classes but Java also uses abstract classes and interfaces to hide details and show essential information. - Encapsulation: Both wrap data and code together, but in Java variables are only accessible through class methods. - Inheritance: Both allow acquiring parent properties, but in Java new

Uploaded by

sabahatfatima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
170 views

Oop Assignment 1

The document provides a comparison of object-oriented programming features between Java and C++, including: - Class definition: In C++ classes declare object specifications but don't allocate memory, while in Java classes create objects that behave like instances of that class. - Object creation: In C++ objects exist at runtime, while in Java objects combine data and procedures working on that data. - Abstraction: Both use classes but Java also uses abstract classes and interfaces to hide details and show essential information. - Encapsulation: Both wrap data and code together, but in Java variables are only accessible through class methods. - Inheritance: Both allow acquiring parent properties, but in Java new

Uploaded by

sabahatfatima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSIGNMENT#01

SUBMITTED TO DR TUFAIL MUHAMMAD


SUBMITTED BY MUHAMMAD TAHIR
REGISTERATION ID 205309
DATED 31/3/21
Q: Provide a detail comparison of Java and C++ with reference to
the Object-Oriented Programing features available in both
languages.

 CLASS DEFINITION:
C++:
A class is initiated in C++ using keyword “class” followed by the
name of class. The body of class is declared inside the curly braces and
terminated by a semicolon at the end. You can declare an objects, when
a class is defined, only the specification for the object is defined, no
memory or storage is allocated.

JAVA:
A class--the basic building block of an object-oriented language
such as Java--is a language that describes the data and behavior
associated with instances of that class. When you initiate a class, you
create an object that looks and feels like other instances of the
same class.
 OBJECT CREATION:
C++:
In C++, object is a real-world entity, for example, chair, car, pen,
mobile, laptop etc. In other words, object is an entity that has state and
behavior. Here, state means data and behavior means
functionality. Object is a runtime entity; it is created at runtime.

JAVA:
A Java object is a combination of data and procedures working
on the available data. An object has a state and behavior. The state of
an object is stored in fields (variables), while methods (functions)
display the object's behavior. Objects are created from templates known
as classes.

 ABSTRACTION:
C++:
Abstraction means displaying only essential information and
hiding the details. Data abstraction refers to providing only essential
information about the data to the outside world, hiding the background
details or implementation. ... Abstraction using Classes: We can
implement Abstraction in C++ using classes.
JAVA:
In Java, abstraction is achieved using Abstract classes and
interfaces.

Data abstraction is the process of hiding certain details and


showing only essential information to the user.
Abstraction can be achieved with either abstract classes or interfaces. 
The abstract keyword is a non-access modifier, used for classes and
methods:

 Abstract class: is a restricted class that cannot be used to create


objects (to access it, it must be inherited from another class).
 Abstract method: can only be used in an abstract class, and it
does not have a body. The body is provided by the subclass
(inherited from).

 ENCAPSULATION:

C++:

In general, encapsulation is a process of wrapping similar code


in one place. In C++, we can bundle data members and functions that
operate together inside a single class. For example, class Rectangle
{public: int length; int breadth; int getArea() { return length *
breadth; } };

JAVA:

Encapsulation in Java is a mechanism of 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.
 INHERITANCE:

C++:

In C++, inheritance is a process in which one object acquires all


the properties and behaviors of its parent object automatically. In such
way, you can reuse, extend or modify the attributes and behaviors which
are defined in other class.

JAVA:

Inheritance in Java is a mechanism in which one object acquires


all the properties and behaviors of a parent object. It is an important part
of OOP (Object Oriented programming system).

The idea behind inheritance in Java is that you can create


new CLASSES that are built upon existing classes. When you inherit
from an existing class, you can reuse methods and fields of the parent
class. Moreover, you can add new methods and fields in your current
class also.

You might also like