Java 2 Mark
Java 2 Mark
1. Define OOP.
Object-Oriented Programming (OOP) is a methodology or paradigm to design a program
using classes and objects. It simplifies the software development and maintenance by
providing some concepts:
○ Object
○ Class
○ Inheritance
○ Polymorphism
○ Abstraction
○ Encapsulation
2. Define object and class.
Any entity that has state and behavior is known as an object. For example: chair, pen,
table, keyboard, bike etc. It can be either physical or logical.
A class is the basic building block of an object-oriented language. It is a template that
describes the data and behavior associated with instances of that class. The data associ-
ated with a class or object is stored in variables and the behavior associated with a class
or object is implemented with methods.
3. How can we create an instance of a class in java?
To create an instance of a class:
Declare an instance identifier (instance name) of a particular class.
Construct the instance (i.e., allocate storage for the instance and initialize the instance)
using the “new” operator.
4. Define Inheritance.
When one object acquires all the properties and behaviours of parent object, it is known
as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.
5. What are the types of inheritance in java?
1. Single Inheritance
2. Multilevel Inheritance
3. Hierarchical Inheritance
4. Hybrid Inheritance
6. Define Polymorphism.
Polymorphism means taking many forms, where „poly‟ means many and „morph‟ means
forms. It is the ability of a variable, function or object to take on multiple forms.
7. Define abstraction.
Hiding internal details and showing functionality is known as abstraction. For example:
phone call, we don‟t know the internal processing.
8. Define encapsulation.
Binding (or wrapping) code and data together into a single unit is known as
encapsulation. For example: capsule, it is wrapped with different medicines.
A java class is the example of encapsulation.
9. List the advantage of OOPs over Procedure-oriented programming language
OOPs makes development and maintenance easier. But in Procedure-oriented program-
ming language, it is not easy to manage if code grows as project size grows.
OOPs provides data hiding whereas in Procedure-oriented programming
language, global data can be accessed from anywhere.
OOPs provides ability to simulate real-world event much more effectively.
We can provide the solution of real word problem if we are using the Object-
Oriented Programming language.
10. What is difference between object-oriented programming language and object-based
programming language?
Object oriented language
Object-oriented language supports all the features of OOPs.
Object-oriented language doesn‟t has in-built object.
Object-oriented languages are C++, C#, Java etc.
If the class is defined inside a package, then the package statement should be the first
statement in the source file.
If import statements are present, then they must be written between the package
statement and the class declaration. If there are no package statements, then the import
statement should be the first line in the source file.
Import and package statements will imply to all the classes present in the source file.
It is not possible to declare different import and/or package statements to different
classes in the source file.
13. Define Jvm.
The JVM is an interpreter for the bytecode form of the program. It steps through one byte-
code instruction at a time. It is an abstract computing machine that enables a computer to
run a Java program.
14. What is bytecode?
Bytecode is a highly optimized set of instructions designed to be executed by the java
run-time system, which is called as java virtual machine (JVM). JVM is an interpreter for
bytecode.
15. Write a note on integer data types in java.
Integers are used for storing integer values. There are four kinds of integer types in Java.
Each of these can hold a different range of values. The values can either be positive or
negative.
type size
byte 8 bits
short 16 bits
int 32 bits
long 64 bits
16. Write a note on float data types in Java.
Float is used to store numbers with decimal part. There are two floating point data types
in Java namely, the float and the double.
type size
float 32 bits
double 64 bits
The whole path of the class must be specified to import a class from the Java library, For
instance, to import the Date class from the util package, the following code is used:
import java.util.Date;
It is also possible to import all classes that belong to a package using the * symbol.
19. List out the features of java.
Simple
Secure
Portable
Object-oriented
Robust
Multithreaded
Architecture-neutral
Interpreted
High performance
Distributed
Dynamic
20. What is the use of comment?
The contents of a comment are ignored by the compiler. Instead, a comment can be used
to describe or explain the operation of the program to anyone who is reading its source
code.
21. What is a variable? How to declare variable in java?
The variable is the basic unit of storage in a java program. A variable is defined by the
combination of an identifier, a type, and an optional initialize. All variables must be de-
clared before they can be used. The basic form of a variable declaration is shown have
Type identifier [= value],[,identifier [=value]]
The type in one of java‟s atomic types. The identifier is the name of the variable. For example
int a,b,c;
int d=3,c=5;
22. What is a variable? What are the different types of variables?
Variable are locations in the memory that can hold values. Java has three kinds of variable
namely,
Instance variable
Local variable
Class variable
23. What are the difference between static variable and instance variable?
The data or variables, defined within a class are called instance variables.Instance vari-
ables declared as static are, essentially, global variables. When objects of its class are
declared, no copy of a static variable is made.
CS8392 Object Oriented Programming Page 4
Sri Vidya College of Engineering & Technology Question Bank
Example:
static int no;
33. Write short notes on static method.
The method declared with static keyword is known as static method. main() is most com-
mon static method.
It belongs to the class and not to object of a class.
A static method can directly access only static variables of class and directly invoke
only static methods of the class.
It can be called through the name of class without creating any instance of that class.
For example, ClassName.methodName()
Example:
static void show(){
System,out.println(“Hello”);
}
34. What do you mean by static import?
The static import allows the programmer to access any static members of imported class
directly. There is no need to qualify it by its name.
Syntax:
import static package_name;
35. What is a static block?
A static block is a block of code enclosed in braces, preceded by the keyword static.
The statements within the static block are first executed automatically before main
when the class is loaded into JVM.
A class can have any number of static blocks.
CS8392 Object Oriented Programming Page 6
Sri Vidya College of Engineering & Technology Question Bank
PART-B
1. Explain about packages. Give an example program which uses packages. (16)
(CS1261 NOV /DEC 2016) (IT2301 NOV/DEC-2012)
2. Explain with the help of a program how object oriented programming overcomes the
shortcomings of procedure oriented programming.(8) (IT2301 APR/MAY-2015)
3. Given two one dimensional arrays A and B which are sorted in ascending order.
Write a Java program to merge them into a single sorted array, see that is contains
every item from array A and B, in ascending order. (8) (IT2301 APR/MAY-2015)
4. With an example, describe in detail about how polymorphism plays a useful role in
Java. (8) (IT2301 APR/MAY-2015)
5. Elaborate on the various object oriented concepts, with necessary illustrations. (16)
(IT2301 MAY/JUNE-2014)
6. Write a program to perform the following functions using classes, objects,
constructors and destructors where essential. (IT2301 MAY/JUNE-2014)
a. Get as input the marks of 5 students in 5 subjects. (4)
b. Calculate the total and average. (8)
c. Print the formatted result on the screen. (4)
7. With suitable examples explain how packages can be created, imported and used.
Also elaborate on its scope. (16) (IT2301 MAY/JUNE-2014)
8. Write a program to perform following functions on a given matrix.
(IT2301 MAY/JUNE-2014)
a. Find the row and column sum. (8)
b. Interchange rows and columns. (8)
9. Describe the structure of Java program. (8) (IT2301 NOV/DEC-2012)
10. Explain the features of Java. (8) (IT2301 NOV/DEC-2012)
11. Write a simple Java program to implement basic Calculator operations. (16)
(CS2311 NOV/DEC-2014)
12. How packages are used to resolve naming conflicts in Java? With an example show to
add classes to packages and how to import packages in classes. (16)
(CS2311 NOV/DEC-2014)
13. Write a program in Java that interchanges the odd and even components of an array
in
Java. (16) (CS2311 APR/MAY-2015)
14. Write a Java program to sort set of names stored in an array in alphabetical order.
(16) (CS2311 APR/MAY-2015)
15. Explain the arrays and its types in detail with example program.
(CS2311 MAY/JUNE-2014)
16. Briefly explain about the key elements of Object Oriented Programming.(16)
(CS1361 NOV/DEC-2014)
17. Explain about Class, Objects and Methods in Java with an example program. (16)
(CS1361 NOV/DEC-2014)
21. Explain the arrays and its types in detail with example program.
(CS2311 MAY/JUNE-2014)
22. Briefly explain about the key elements of Object Oriented Programming.(16)
(CS1361 NOV/DEC-2014)
23. Explain about Class, Objects and Methods in Java with an example program. (16)
(CS1361 NOV/DEC-2014)
24. Describe the following: (CS1361 NOV/DEC-2014)
a. Features of Java (8)
b. Data types in Java (8)
25. Explain about Package in Java. List built in Java API packages. (16)
(CS1361 NOV/DEC-2014)
26. Discuss the various parameter passing methods in Java. Illustrate with examples.
(CS1361 NOV/DEC-2014)