Oop with c++ and java

http://www.indiabix.com/computer-science/object-oriented-programming-using-cpp/094001

http://www.codeproject.com/Articles/22769/Introduction-to-Object-Oriented-ProgrammingConcep

http://www.ntu.edu.sg/home/ehchua/programming/java/J3a_OOPBasics.html

http://www.javatpoint.com/java-oops-concepts

http://www.studytonight.com/cpp/introduction-to-cpp.php

1.what is the difference between procedural and object oriented proramming

Object-oriented programming, or OOP, is an approach to problem-solving where all computations are carried out using objects. An object is a component of a program that knows how to perform certain actions and how to interact with other elements of the program. Objects are the basic units of object-oriented programming. A simple example of an object would be a person. Logically, you would expect a person to have a name. This would be considered a property of the person. You would also expect a person to be able to do something, such as walking. This would be considered a method of the person.

A method in object-oriented programming is like a procedure in procedural programming. The key difference here is that the method is part of an object. In object-oriented programming, you organize your code by creating objects, and then you can give those objects properties and you can make them do certain things.

A key aspect of object-oriented programming is the use of classes. A class is a blueprint of an object. You can think of a class as a concept, and the object as the embodiment of that concept. So let’s say you want to use a person in your program. You want to be able to describe the person and have the person do something. A class called ‘person’ would provide a blueprint for what a person looks like and what a person can do. Examples of object-oriented languages include C#, Java, Perl and Python.

Key Differences
One of the most important characteristics of procedural programming is that it relies on procedures that operate on data – these are two separate concepts. In object-oriented programming, these two concepts are bundled into objects. This makes it possible to create more complicated behavior with less code. The use of objects also makes it possible to reuse code. Once you have created an object with more complex behavior, you can use it anywhere in your code.

Let’s look at a simple example of this. You want to write a program that plays a song. Your band playing the song will have four members, and you start off by given each of them a name:

myband = (‘John,’ ‘Paul,’ ‘George,’ ‘Ringo’)

Now that you have your band, it’s time to pick the song:

mysong = ‘Yellow Submarine’

Object-oriented programming, or OOP, is an approach to problem-solving where all computations are carried out using objects. An object is a component of a program that knows how to perform certain actions and how to interact with other elements of the program. Objects are the basic units of object-oriented programming. A simple example of an object would be a person. Logically, you would expect a person to have a name. This would be considered a property of the person. You would also expect a person to be able to do something, such as walking. This would be considered a method of the person.

A method in object-oriented programming is like a procedure in procedural programming. The key difference here is that the method is part of an object. In object-oriented programming, you organize your code by creating objects, and then you can give those objects properties and you can make them do certain things.

A key aspect of object-oriented programming is the use of classes. A class is a blueprint of an object. You can think of a class as a concept, and the object as the embodiment of that concept. So let’s say you want to use a person in your program. You want to be able to describe the person and have the person do something. A class called ‘person’ would provide a blueprint for what a person looks like and what a person can do. Examples of object-oriented languages include C#, Java, Perl and Python.

Key Differences
One of the most important characteristics of procedural programming is that it relies on procedures that operate on data – these are two separate concepts. In object-oriented programming, these two concepts are bundled into objects. This makes it possible to create more complicated behavior with less code. The use of objects also makes it possible to reuse code. Once you have created an object with more complex behavior, you can use it anywhere in your code.

Let’s look at a simple example of this. You want to write a program that plays a song. Your band playing the song will have four members, and you start off by given each of them a name:

myband = (‘John,’ ‘Paul,’ ‘George,’ ‘Ringo’)

Now that you have your band, it’s time to pick the song:

mysong = ‘Yellow Submarine’

2.what is class

A class is simply a representation of a type of object. It is the blueprint, or plan, or template, that describes the details of an object. A class is the blueprint from which the individual objects are created. Class is composed of three things: a name, attributes, and operations.

Difference between object and class

There are many differences between object and class. A list of differences between object and class are given below:

No. Object Class
1) Object is an instance of a class. Class is a blueprint or template from which objects are created.
2) Object is a real world entity such as pen, laptop, mobile, bed, keyboard, mouse, chair etc. Class is a group of similar objects.
3) Object is a physical entity. Class is a logical entity.
4) Object is created through new keyword mainly e.g.
Student s1=new Student(); Class is declared using class keyword e.g.
class Student{}
5) Object is created many times as per requirement. Class is declared once.
6) Object allocates memory when it is created. Class doesn’t allocated memory when it is created.
7) There are many ways to create object in java such as new keyword, newInstance() method, clone() method, factory method and deserialization. There is only one way to define class in java using class keyword.

3.what is eencapsulation???????

The encapsulation is the inclusion-within a program object-of all the resources needed for the object to function, basically, the methods and the data. In OOP the encapsulation is mainly achieved by creating classes, the classes expose public methods and properties. A class is kind of a container or capsule or a cell, which encapsulate a set of methods, attribute and properties to provide its indented functionalities to other classes. In that sense, encapsulation also allows a class to change its internal implementation without hurting the overall functioning of the system. That idea of encapsulation is to hide how a class does its business, while allowing other classes to make requests of it.

4.what is method overloading ?

If a class have multiple methods by same name but different parameters, it is known as Method Overloading.

If we have to perform only one operation, having same name of the methods increases the readability of the program.

Suppose you have to perform addition of the given numbers but there can be any number of arguments, if you write the method such as a(int,int) for two parameters, and b(int,int,int) for three parameters then it may be difficult for you as well as other programmers to understand the behaviour of the method because its name differs. So, we perform method overloading to figure out the program quickly.
Advantage of method overloading?

Method overloading increases the readability of the program.

Different ways to overload the method

There are two ways to overload the method in java
By changing number of arguments
By changing the data type

5.what is constructor

Constructor in java is a special type of method that is used to initialize the object.

Java constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object that is why it is known as constructor.

Rules for creating java constructor

There are basically two rules defined for the constructor.

Constructor name must be same as its class name
Constructor must have no explicit return type
Types of java constructors

There are two types of constructors:

Default constructor (no-arg constructor)
Parameterized constructor

6.what is static variable and  static method

The static keyword in java is used for memory management mainly. We can apply java static keyword with variables, methods, blocks and nested class. The static keyword belongs to the class than instance of the class.The static keyword in java is used for memory management mainly. We can apply java static keyword with variables, methods, blocks and nested class. The static keyword belongs to the class than instance of the class.

Static variables when used inside function are initialized only once, and then they hold there value even through function calls.

If you apply static keyword with any method, it is known as static method.

A static method belongs to the class rather than object of a class.
A static method can be invoked without the need for creating an instance of a class.
static method can access static data member and can change the value of it.

6.why java main method is static?

Ans) because object is not required to call static method if it were non-static method, jvm create object first then call main() method that will lead the problem of extra memory allocation.

7. what is Java static block

Is used to initialize the static data member.
It is executed before main method at the time of classloading

8.what is inheritance?

Inheritance is the capability of one class to acquire properties and characteristics from another class. The class whose properties are inherited by other class is called the Parent or Base or Super class. And, the class which inherits properties of other class is called Child or Derived or Sub class.

Inheritance makes the code reusable. When we inherit an existing class, all its methods and fields become available in the new class, hence code is reused.

9.what is Polymorphism?

Polymorphism means having multiple forms of one thing. In inheritance, polymorphism is done, by method overriding, when both super and sub class have member function with same declaration bu different definition.

If we inherit a class into the derived class and provide a definition for one of the base class’s function again inside the derived class, then that function is said to be overridden, and this mechanism is called Function Overriding


Requirements for Overriding

  1. Inheritance should be there. Function overriding cannot be done within a class. For this we require a derived class and a base class.
  2. Function that is redefined must have exactly the same declaration in both base and derived class, that means same name, same return type and same parameter list.

Leave a comment