Java_Scheam&Solution-1
Java_Scheam&Solution-1
Kumbalgodu, Bangalore-74
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
Scheme & Solutions
INTERNALS ASSESSMENT-I
Subject : Object Oriented Programming with
JAVA
Subject Code : BCS306A
Semester& Section : III CSE (A,B,C)
Q.No Scheme & Solutions Marks
1.a Explain the following object oriented concepts:
i) Polymorphism
can be thought of as one interface, multiple methods. It is a feature that allows one interface to
be used for a general class of actions
ii) Encapsulation 3
bind the data and code working on that data into a single entity 3
iii) Inheritance
allows us to have code re-usability. It is a process by which one object can acquire the
properties of another object 4
b What are Keywords and Identifiers? List the rules to write an identifier.
Keywords : There are 50 keywords currently defined in the Java. These keywords, 3
combined with the syntax of the operators and separators, form the foundation of the Java
language. These keywords cannot be used as names for a variable, class, or method.
Identifiers : Identifiers are used for class names, method names, and variable names. An 3
identifier may be any sequence of uppercase and lowercase letters,
numbers, or the underscore and dollar- sign characters. They must not begin
with a number. As Java is case-sensitive, Avg is a different identifier than
avg. 4
Examples of valid identifiers: Avg, sum1,
$x, sum_sq etc. Examples of invalid
2.a identifiers: 2sum, sum-sq, x/y etc.
Define a class and object. Write syntax to create class and object with an Example.
class Box
{
double w, h, d;
}
class BoxDemo
{
public static void main(String args[])
{
Box b1=new Box(); Box b2=new Box(); double vol;
The short-circuit AND (&&) and OR (||) operators will not evaluate the second operand if
the first is decisive. For example,
int x=0, n=5;
……..
if(x!=0 && n/x > 0)
//do something
5
ii) for Loop
The general form is –
for(initialization; condition; updation)
{
// body of loop
}
for-each Loop
for(type itr-var : collection)
statement-block
Example:
int nums[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int sum = 0;
for(int x: nums) 5
sum += x;
4.a Develop a JAVA program to add TWO matrices of suitable order N (The value of N should
be read from command line arguments).
int N = Integer.parseInt(args[0]);
int counter = 1;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
matrixA[i][j] = counter;
matrixB[i][j] = counter * 2;
counter++;