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

Java_Scheam&Solution-1

The document outlines the internal assessment for Object Oriented Programming with Java at Rajarajeshwari College of Engineering, detailing various topics such as polymorphism, encapsulation, inheritance, keywords, identifiers, class and object definitions, and Java operators. It includes questions on compiling and running Java applications, matrix addition, stack implementation, method overloading, and constructor overloading with example programs. The assessment is structured into multiple questions with specific marks allocated for each part.

Uploaded by

kenkaneki6120
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Java_Scheam&Solution-1

The document outlines the internal assessment for Object Oriented Programming with Java at Rajarajeshwari College of Engineering, detailing various topics such as polymorphism, encapsulation, inheritance, keywords, identifiers, class and object definitions, and Java operators. It includes questions on compiling and running Java applications, matrix addition, stack implementation, method overloading, and constructor overloading with example programs. The assessment is structured into multiple questions with specific marks allocated for each part.

Uploaded by

kenkaneki6120
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

RAJARAJESWARI COLLEGE OF ENGINEERING

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;

b1.w=2; b1.h=4; b1.d=3;


b2.w=5; b2.h=6; b2.d=2;
vol=b1.w*b1.h*b1.d; System.out.println("Volume of Box1 is " + vol);

vol=b2.w*b2.h*b2.d; System.out.println("Volume of Box2 is " + vol);


}
} 10
b. i) Explain the process of compiling and running the java application with the help of “Hello
World” program
class Prg1
{
public static void main(String args[ ])
{
System.out.println(“Hello World!!!”);
}
}
javac Prg1.java
java Prg1

The output of the program will now be displayed as – 5


Hello World!!!

ii) Write a java program to find the area of circle.


class Area
{
public static void main(String args[])
{
double pi, r, a; r = 10.8;
pi = 3.1416;
a = pi * r * r;
5
System.out.println("Area of circle is " + a);
}
}

3.a Explain the following operators with an example.


i) >> ii) >>> iii) << iv) ? v) %=
i)
int a = 35; //00100011 is the binary equivalent
a = a >> 2; // now, a contains 8
ii) int a = -1;
a = a >>> 24;
Here is the same operation in binary form to further illustrate what is happening:
11111111 11111111 11111111 11111111 –1 in binary as an int
>>>24
00000000 00000000 00000000 11111111 255 in binary as an int
iii) int a = 64; //0100 0000 is the binary equivalent
a = a <<2; // now, a contains 256
iv) var = expression1 ? expression2 : expression3;
int a, b, c ;
……….
c= (a>b)?a:b; //c will be assigned with biggest
among a and b
v) The % operator returns the remainder after division. It can be applied on integer and
floating-point types. For example,
int x=57; double y= 32.8;
x%=10;
y%=10;
System.out.println(“on integer “ + x); //prints 7
System.out.println(“on double “ + y); //prints 2.8 10
b Explain the difference between the following.
i) Logical AND and short circuit AND
ii) for loop and foreach loop with suitable example.
i) All of the binary logical operators combine two boolean values to form a resultant boolean
value.
boolean a = true; boolean b = false;
boolean d = a & b; //d=false

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++;

for (int i = 0; i < N; i++) {


for (int j = 0; j < N; j++) { 10
resultMatrix[i][j] = matrixA[i][j] + matrixB[i][j];

b Write a Java program to implement stack of 5 integers.


class Stack
{
int st[] = new int[5]; int top;
Stack()
{
top = -1;
}
void push(int item)
{
if(top==4)
System.out.println("Stack is full.");
else
st[++top] = item;
}
int pop()
{
if(top==-1)
{System.out.println("Stack underflow."); return 0;
}
else 10
return st[top--];
}
}
5.a
What is Overloading? Explain the Overloading with suitable example.
class Overload
{
void test() //method without any arguments
{
System.out.println("No parameters");
}
void test(int a) //method with one integer argument
{
System.out.println("Integer a: " + a);
}
void test(int a, int b) //two arguments
{
System.out.println("With two arguments : " + a + " " + b);
}
void test(double a) //one argument of double type
{
System.out.println("double a: " + a);
10
}
}
b
What is constructor? Explain constructor overloading with suitable example program.
class Box
{
double w, h, d;
double volume()
{
return w*h*d;
}
Box() //ordinary constructor
{
w=h=d=5; 10
}
Box(double wd, double ht, double dp) //parameterized constructor
{
w=wd; h=ht; d=dp;}}

You might also like