Home | | Object Oriented Programming | Important Short Questions and Answers: OOP - Overview of Java

Chapter: Object Oriented Programming(OOP) : Overview of Java

Important Short Questions and Answers: OOP - Overview of Java

Object Oriented Programming(OOP) - Overview of Java - Important Short Questions and Answers: OOP - Overview of Java


1) What is meant by Object Oriented Programming?

 

OOP is a method of programming in which programs are organised as cooperative collections of objects. Each object is an instance of a class and each class belong to a hierarchy.

 

2) What is a Class?

 

Class is a template for a set of objects that share a common structure and a common behaviour.

 

3) What is an Object?

 

Object is an instance of a class. It has state,behaviour and identity. It is also called as an instance of a class.

 

4) What are methods and how are they defined?

 

Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above.

 

5) What are different types of access modifiers (Access specifiers)?

Access specifiers are keywords that determine the type of access to the member of a class. These keywords are for allowing privileges to parts of a program such as functions and variables. These are: public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private can’t be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages.

 

default modifier : Can be accessed only to classes in the same package.

6) What is an Object and how do you allocate memory to it?

 

Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.

 

7) Explain the usage of Java packages.

 

This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes.

 

8) What is method overloading and method overriding?

 

Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.

 

9) What gives java it’s “write once and run anywhere” nature?

 

All Java programs are compiled into class files that contain bytecodes. These byte codes can be run in any platform and hence java is said to be platform independent.

 

10) What is a constructor? What is a destructor?

Constructor is an operation that creates an object and/or initialises its state. Destructor is an operation that frees the state of an object and/or destroys the object itself. In Java, there is no concept of destructors. Its taken care by the JVM.

 

11) What is the difference between constructor and method?

 

Constructor will be automatically invoked when an object is created whereas method has to be called explicitly

 

12) What is Static member classes?

 

A static member class is a static member of a class. Like any other static method, a static member class has access to all static methods of the parent, or top-level, class.

 

13) What is Garbage Collection and how to call it explicitly?

 

When an object is no longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection. System. gc() method may be used to call it explicitly

 

14) In Java, How to make an object completely encapsulated?

 

All the instance variables should be declared as private and public getter and setter methods should be provided for accessing the instance variables.

 

15) What is the difference between String and String Buffer?

 

a) String objects are constants and immutable whereas StringBuffer objects are not. b) String class supports constant strings whereas StringBuffer class supports growable and modifiable strings.

 

16) What is the difference between Array and vector?

 

Array is a set of related data type and static whereas vector is a growable array of objects and dynamic

 

17) What is the difference between this() and super()?

 

this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.

 

18) Explain working of Java Virtual Machine (JVM)?

 

JVM is an abstract computing machine like any other real computing machine which first converts .java file into .class file by using Compiler (.class is nothing but byte code file.) and Interpreter reads byte codes.

 

19) What is meant by Inheritance and what are its advantages?

 

Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.

 

20) Differentiate between a Class and an Object?

 

The Object class is the highest-level class in the Java class hierarchy. The Class class is used to represent the classes and interfaces that are loaded by a Java program. The Class class is used to obtain information about an object's design. A Class is only a definition or prototype of real life object. Whereas an object is an instance or living representation of real life object. Every object belongs to a class and every class contains one or more related objects.

 

21) What is an Interface?

 

Interface is an outside view of a class or object which emphaizes its abstraction while hiding its structure and secrets of its behaviour.

 

22) What is a base class?

 

Base class is the most generalised class in a class structure. Most applications have such root classes. In Java, Object is the base class for all classes.

 

23)Define inheritance?

The mechanism of deriving a new class from an old one is called inheritance. The

 

old class is referred to as the base class and the new one is called the derived class or the subclass.

 

24)What are the types in inheritance?

i. Single inheritance

 

ii. Multiple inheritance iii.Multilevel inheritance

iv.Hierarchical inheritance

v. Hybrid inheritance

25) Explain single inheritance?

 

A derived class with only one base class is called single inheritance 26)What is multiple inheritance?

 

A derived class with more than one base class is called multiple inheritance. 27)Define hierarchical inheritance?

 

One class may be inherited by more than one class. This process is known as hierarchical inheritance.

 

28)What is hybrid inheritance?

 

There could be situations where we need to apply two or more type of inheritance to design a program. This is called hybrid inheritance.

 

29)What is multilevel inheritance?

 

The mechanism of deriving a class from another derived class is known as multilevel inheritance.

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Object Oriented Programming(OOP) : Overview of Java : Important Short Questions and Answers: OOP - Overview of Java |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.