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

Unit 1

The document contains questions and answers related to object-oriented programming (OOP) and Java fundamentals. It discusses the key OOP principles like abstraction, encapsulation, inheritance and polymorphism. It also covers features of Java like being object-oriented, platform independent, secure etc. Specific concepts defined include classes, objects, methods, constructors, variables and data types in Java.

Uploaded by

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

Unit 1

The document contains questions and answers related to object-oriented programming (OOP) and Java fundamentals. It discusses the key OOP principles like abstraction, encapsulation, inheritance and polymorphism. It also covers features of Java like being object-oriented, platform independent, secure etc. Specific concepts defined include classes, objects, methods, constructors, variables and data types in Java.

Uploaded by

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

ADITHYA INSTITUTE OF TECHNOLOGY

COIMBATORE – 641 107


Degree: B.Tech. & Branch: IT
Semester: 03 & Year: II
CS8392 – OBJECT ORIENTED PROGRAMMING
Question Bank
UNIT: 1 – INTRODUCTION TO OOP AND JAVA FUNDAMENTALS
PART - A

1. What are the OOP Principles?


The principles of object-oriented programming is Class, inheritance, interface
implementation, abstraction of data and behavior, encapsulation of data and class
implementation, polymorphism and virtual methods.

2. What are the four cornerstones of OOP?


 Abstraction: Can manage complexity through abstraction. Gives the complete
overview of a particular task and the details are handled by its derived classes.
Example: Car.
 Encapsulation: Nothing but data hiding, like the variables declared under private
of a particular class is accessed only in that class and cannot access in any other the
class.
 Inheritance: Is the process in which one object acquires the properties of another
object, ie., derived object.
 Polymorphism: One method different forms, ie., method overriding and interfaces
are the examples of polymorphism.

3. What are the features of Object Oriented Programming?


 Emphasis is on data rather than procedure.
 Programs are divided into objects.
 Data structures are designed such that they characterize the objects.
 Functions that operate on the data of an object are tied together.
 Data is hidden and cannot be accessed by external functions.
 Objects may communicate with each other through functions.
 New data and functions can easily be added whenever necessary.
 Follows bottom-up approach.

4. What are the features of Java Language?


The features of Java Language are Simple, Object-Oriented, Portable, Platform
independent, Secured, Robust, Architecture neutral, Dynamic, Interpreted, High
Performance, Multithreaded and Distributed.

5. How Java supports platform independency?


The meaning of platform independent is that, the java source code can run on all
operating systems. a compiler is a program that translates the source code for another
program from a programming language into executable code. This executable code

1
may be a sequence of machine instructions that can be executed by the CPU directly,
or it may be an intermediate representation that is interpreted by a virtual machine.
This intermediate representation in Java is the Java Byte Code.

6. What is Java Interpreter?


It is a Java Virtual Machine. An interpreter is a program that reads in as input a
source program, along with data for the program, and translates the source
program instruction by instruction. For example, the Java interpreter java translates
a .class file into code that can be executed natively on the underlying machine.

7. Give any 4 differences between C and Java.


C Java
C is a procedural Language Java is Object Oriented Language
C is a compiled language. Java is an Interpreted language
C uses the top-down {sharp & smooth} JAVA uses the bottom-up {on the
approach rocks}
approach.
C does not support overloading JAVA supports Method Overloading

8. Distinguish between procedure oriented programming (POP) and Object oriented


programming.(OOP)
POP OOP
In POP, program is divided into In OOP, program is divided into parts
small parts called functions. called objects.
POP does not have any access OOP has access specifiers named Public,
specifier. Private, Protected, etc.
POP does not have any proper way OOP provides Data Hiding so provides
for hiding data so it is less secure. more security.
In POP, Overloading is not possible. In OOP, overloading is possible in the
form of Function Overloading and
Operator Overloading.
In POP, Most function uses Global In OOP, data cannot move easily from
data for sharing that can be accessed function to function, it can be kept public
freely from function to function in the or private so we can control the access of
system. Example of POP are : C, data.
VB, FORTRAN, Pascal Example of OOP are : C++, JAVA,
VB.NET, C#.NET.

9. What are the data types supported in Java?


Operator in java is a symbol that is used to perform operations like +, -, *, / etc.
There are many types of operators in java which are Unary Operator, Arithmetic
Operator, Shift Operator, Relational Operator, Bitwise Operator, Logical Operator,

2
Ternary Operator and, Assignment Operator.

10. Define Abstraction.


Abstraction refers to the act of representing the essential features without including
the background details or explanations. It reduces the complexity and increases the
efficiency. Small programs can be easily upgraded to large programs. Software
complexity can easily be managed.

11. What is Polymorphism?


Polymorphism is the ability to take more than one form and refers to an operation
exhibiting different behavior instances. Object oriented programs use polymorphism to
carry out the same operation in a manner customized to the object. It allows a single
name/operator to be associated with different operation depending on the type of data
passed to it.

12. Define Objects and Classes in Java


Class is a collection of data and the function that manipulate the data. The data
components of the class are called data fields and the function components of the
class are called member functions or methods. The class that contains main function is
called main class.
Object is an instance of a class. The objects represent real world entity. The objects
are used to provide a practical basis for the real world. Objects are used to
understand the real world. The object can be declared by specifying the name of the
class.

13. Write the syntax for declaration of class and creation of objects?
A class is declared using class keyword. A class contains both data and method that
operate on that data. Thus, the instance variables and methods are known as class
members. When creating an object from a class
Declaration − A variable declaration with a variable name with an object type.
Instantiation − The 'new' keyword is used to create the object.
Initialization − The 'new' keyword is followed by a call to a constructor. This call
initializes the new object.
class Student
{
String name; int rollno; int age;
}
Student std=new Student();
 std is instance/object of Student class.
 new keyword creates an actual physical copy of the object and assign it to the
std variable.

3
 The new operator dynamically allocates memory for an object.

14. Define Encapsulation (Apr/May 2012) (Apr 2017)


The wrapping up of data and functions into a single unit is known as data
encapsulation. Here the data is not accessible to the outside the class. The data inside
that class is accessible by the function in the same class. It is normally not accessible
from the outside of the component.

15. What is Inheritance? What are its types?


 Inheritance is a mechanism of reusing the properties and extending existing
classes without modifying them, thus producing hierarchical relationships
between them.
 Inheritance is a property by which the new classes are created using the old
classes.
 The old classes are referred as base classes and the new classes are referred as
derived classes. That means the derived classes inherit the properties of base
class.
 extends and implements keywords are used to describe inheritance in Java.
Types of inheritance are: Single inheritance, Multi-level inheritance, Hierarchical
inheritance, Hybrid inheritance.
Syntax :
class Subclass-name extends Superclass-name
{ //methods and fields }

16. Define class[NOV/DEC 2011]


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

4
17. What do you mean by Dynamic Initialization?
Java is a flexible programming language which allows the dynamic initialization of
variables. In other words, at the time of declaration one can initialize the variables. In
java we can declare the variable at any place before it is used. Example: int a=10;
float d=2.34f;

18. What do you mean by Variable? What are the rules for variable declaration?
Variable is a fundamental unit of storage in java. The variables are used in
combination with identifiers, data types, operators and some value for initialization.
The syntax of variable declaration will be:
data_type name_of_variable[=initialization];

19. What is difference between Methods and Constructor?


A constructor is a member function of a class that is used to create objects of that class.
It has the same name as the class itself, has no return type, and is invoked using the
new operator.
A method is an ordinary member function of a class. It has its own name, a return
type (which may be void), and is invoked using the dot operator.

20. What is Garbage collection?


Objects are dynamically allocated by using the new operator, dynamically allocated
objects must be manually released by use of a delete operator. Java takes a different
approach; it handles deallocation automatically this is called garbage collection.
When no references to an object exist, that object is assumed to be no longer needed,
and the memory occupied by the object can be reclaimed. Garbage collection only
occurs sporadically (if at all) during the execution of your program. It will not occur
simply because one or more objects exist that are no longer used.

21. What is Constructors in Java? What are its types?


A constructor is a special method that is used to initialize an object. The name of the
constructor and the name of the class must be the same. A constructor does not have any
return type. The constructor invoked whenever an object of its associated class is created.
It is called constructor because it creates the values for the data fields of the class.
A constructor has same name as the class in which it resides. Constructor in Java
cannot be abstract, static, final or synchronized. These modifiers are not allowed for
constructors.
Class Car
{
String name; String model;
Car() //Constructor
{
name=””; model=””;}}

5
There are two types of Constructor
 Default Constructor
 Parameterized constructor
Each time a new object is created at least one constructor will be invoked.
Car c=new Car(); //Default constructor invoked
Car c=new Car(name); //Parameterized constructor invoked

22. What is array? How to declare array and how to allocate the memory to for array?
Java array contains elements of similar data type. It is a data structure where we store
similar elements. We can store only fixed set of elements in a java array. Array in
java is index based, first element of the array is stored at 0 index.
data_type array_name []; and to allocate the memory-
array_name=new data_type[size];where array_name represent name of the array, new
is a keyword used to allocate the memory for arrays, data_type specifies the data type of
array elements and size represents the size of an array. For example:int a=new int[10];

23. What's the difference between an interface and an abstract class?


An abstract class may contain code in method bodies, which is not allowed in an
interface. With abstract classes, you have to inherit your class from it and Java does
not allow multiple inheritance. On the other hand, you can implement multiple
interfaces in your class.

24. List any four Java Doc comments. [NOV/DEC 2011]


A Javadoc comment is set off from code by standard multi-line comment tags /* and */.
The opening tag, however, has an extra asterisk, as in /**.The first paragraph is a
description of the method documented. Following the description are a varying number
of descriptive tags, signifying: The parameters of the method (@param),What the
method returns (@return) and any exceptions the method may throw (@throws)

25. What are the access specifiers/modifiers for classes in Java?


Java Access Specifiers (also known as Visibility Specifiers) regulate access to
classes, fields and methods in java. These specifiers determine whether a field or
method in c lass, can be used or invoked by another method in another class or sub-
class. Access Specifiers can be used to restrict access. There are 4 types of java
access modifiers: Private, Default, Protected and Public

26. What is a package?


A java package is a group of similar types of classes, interfaces and sub-packages.
Package in java can be categorized in two form, built-in package and user-defined
package. There are many built-in packages such as java, lang, awt, javax, swing, net,
io, util, sql etc.

6
27. What are the control flow statements in java?
A programming language uses control statements to control the flow of execution of
program based on certain conditions. These are used to cause the flow of execution
to advance and branch based on changes to the state of a program.
Java’s Selection statements:
 if
 if-else
 nested-if
 if-else-if
 switch-case
 jump – break, continue, return
These statements allow you to control the flow of your program’s execution based
upon conditions known only during run time.

Prepared By
Rupilaa V M

You might also like