Department of Information Technology
III Semester
20IT302 – OBJECT ORIENTED PROGRAMMING
Regulation 2020
Unit-I
Question Bank
PART- A
Q.No Questions Marks CO BL
1 What is meant by Object Oriented Programming? 2 CO1 L1
Object-oriented programming (OOP) is a style of programming characterized by the identification of classes
of objects closely linked with the methods (functions) with which they are associated. It also includes ideas
of inheritance of attributes and methods.
2 Define type casting with example. 2 CO1 L2
Typecasting, or type conversion, is a method of changing an entity from one data type to another. ... An
example of typecasting is converting an integer to a string. This might be done in order to compare two
numbers, when one number is saved as a string and the other is an integer.
3 What is byte code? 2 CO1 L1
Java byte code is the instruction set for the Java Virtual Machine. It acts similar to an assembler which is an
alias representation of a C++ code. As soon as a java program is compiled, java byte code is generated. In
more apt terms, java byte code is the machine code in the form of a .class file. With the help of java byte
code we achieve platform independence in java.
4 Write a java program to concatenate two strings. 2 CO1 L1
class Example1
{
public static void main(String args[])
{
String s="Sachin";
s=s.concat(" Tendulkar");
System.out.println(s);
}
}
Output
Sachin Tendulkar
Write a java program to copy the elements of one array to
5 2 CO1 L2
another array.
//Java Program to copy a source array into a destination array in Java
class TestArrayCopyDemo
{
public static void main(String[] args)
{
//declaring a source array
char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e', 'i', 'n', 'a', 't', 'e', 'd' };
//declaring a destination array
char[] copyTo = new char[7];
//copying array using System.arraycopy() method
, System.arraycopy(copyFrom, 2, copyTo, 0, 7);
//printing the destination array
System.out.println(String.valueOf(copyTo));
}
}
Output
caffein
6 Examine the use of break statement with an example 2 CO1 L2
break statement is used to break the current flow of the program and transfer the control to the next
statement outside a loop or switch statement.
breakExample.java
public class BreakExample
{
public static void main(String[] args) {
// TODO Auto-generated method stub
for(int i = 0; i<= 10; i++) {
System.out.println(i);
if(i==6) {
break;
}
}
}
}
Output
0
1
2
3
4
5
6
7 What is meant by Garbage Collection? 2 CO1 L1
A Definition of Java Garbage Collection. Java garbage collection is the process by which Java programs
perform automatic memory management. Java programs compile to byte code that can be run on a Java
Virtual Machine or JVM for short. The garbage collector finds these unused objects and deletes them to free
up memory.
8 Write a java program to convert integer 200 in to String “200” 2 CO1 L2
//Java Program to demonstrate the conversion of String into int
//using Integer.parseInt() method
public class StringToIntExample1
{
public static void main(String args[])
{
//Declaring String variable
String s="200";
//Converting String into int using Integer.parseInt()
int i=Integer.parseInt(s);
//Printing value of i
System.out.println(i);
}
, }
Output
200
9 What is a constructor? What is a destructor? 2 CO1 L1
Constructors are special class functions which performs initialization of every object. The Compiler calls the
Constructor whenever an object is created. Whereas, Destructor on the other hand is used to destroy the class
object.
10 . Describe the purpose of the keyword “final”
final is a non-access modifier applicable only to a variable, a method or a class.
When a variable is declared with final keyword, its value can't be modified, essentially, a constant.
11. Define A Java virtual machine (JVM)
It is an implementation of the Java Virtual Machine Specification,.
It interprets compiled bytecode in to machine code.
12. Describe default constructor.
A default constructor has no parameters, or all the parameters have default values. It is
an inline public member of its class. The compiler will implicitly define A::A() when
uses this constructor to create an object of type A .
13. Describe wrapper classes? Why the wrapper classes are defined as final
Each of Java's eight primitive data types has a class dedicated to it. These are known as wrapper
classes because they "wrap" the primitive data type into an object of that class. The wrapper classes
are part of the java.lang package, which is imported by default into all Java programs,
14. Illustrate the usage of super keyword.
It is used inside a sub-class method definition to call a method defined in the super class.Only public
and protected methods can be called by the super keyword. It is also used by class constructors to
nvoke constructors of its parent class.
15. State objects and object variable.
The Object is the instance itself, whereas the Object Variable is the reference to the Object.
Example: Object o = new Object(); Object ref1 = o; In his case, there is a single instance of the
Object, but it is referenced by two Object Variables: o and ref1.
16.Give any four application areas of oops.
i. Real-time systems.
ii. Simulation and modeling.
iii. Object-oriented databases.
iv. AI and expert systems.
17.List any four advantages of oops.
i. The principle of data hiding helps the programmer to build secure programs that