Object Oriented Programming - Part 4

What is Constructor ?

  • A constructor is a special method whose task is to initialize the object of its class.
  • It is special because its name is the same as the class name.
  • They do not have return types, not even void and therefore they cannot return values.
  • They cannot be inherited, though a derived class can call the base class constructor.
  • Constructor is invoked whenever an object of its associated class is created.

    How does the Java default constructor be provided ?

    If a class defined by the code does not have any constructor, compiler will automatically provide one no-parameter-constructor (default-constructor) for the class in the byte code. The access modifier (public/private/etc.) of the default constructor is the same as the class itself.

    Can constructor be inherited ?

    No, constructor cannot be inherited, though a derived class can call the base class constructor.

    What is multithreading ?

    Multithreading is a process of executing multiple threads simultaneously.Its main advantage is:
  • Threads share the same address space.
  • Thread is lightweight.
  • Cost of communication between process is low.

    What is thread ?

    A thread is a lightweight subprocess.It is a separate path of execution.It is called separate path of execution because each thread runs in a separate stack frame.

    What is deadlock ?

    Deadlock is a situation when two threads are waiting on each other to release a resource. Each thread waiting for a resource which is held by the other waiting thread.

    What do you understand by a variable ?

    Variable is a named memory location that can be easily referred in the program. The variable is used to hold the data and it can be changed during the course of the execution of the program.

    What is data encapsulation ?

    Encapsulation may be used by creating ‘get’ and ’set’ methods in a class (JAVABEAN) which are used to access the fields of the object. Typically the fields are made private while the get and set methods are public. Encapsulation can be used to validate the data that is to be stored, to do calculations on data that is stored in a field or fields, or for use in introspection (often the case when using java beans in Struts, for instance). Wrapping of data and function into a single unit is called as data encapsulation. Encapsulation is nothing but wrapping up the data and associated methods into a single unit in such a way that data can be accessed with the help of associated methods. Encapsulation provides data security. It is nothing but data hiding.

    What is the difference between java and C++ ?

  • Java is a true object - oriented language while C++ is basically c with object-oriented extension.
  • C++ supports multiple inheritance but Java provides interfaces in case of multiple inheritance.
  • Java does not support operator overloading.
  • Java does not have template classes as in C++.
  • Java does not use pointers.
  • Java does not support destructors

    What is run time polymorphism and compile time polymorphism ?

    Compile time polymorphism is also called method overloading, early binding and static binding . in this compiler checks the signature of methods. In run time polymorphism its decide which function is to call. it is also called method overriding, late binding, and dynamic binding.

    What is difference between object oriented programming language and object based programming language ?

    Object based programming languages follow all the features of OOPs except Inheritance. Examples of object based programming languages are JavaScript, VBScript etc.

    Object Oriented Programming - Part 1 >>>

    Home Clouds