L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
UNIT 7- CLASS, OBJECT AND METHOD PART 1
TOPIC NAME:- GENERAL FORM OF CLASS (MCQS)
What is output of following code?
class Box{
Memory address of
public static void main(String[] args){
487 7 A 1 allocated memory of NULL Any arbitrary pointer Garbage
Box obj = new Box();
object
System.out.print(obj);
}}
Which of these keywords is used to make a class?
488 7 A 1 class struct int none of the mentioned
__________ represents an entity in the real world that can be distinctly
489 7 B 1 A class An object A method A data field
identified.
490 7 _______ is a construct that defines objects of the same type. A 1 A class An object A method A data field
491 7 Which of given is not the characteristics of OOPS? D 0.5 abstraction polymorphism encapsulation Object
TOPIC NAME:- GENERAL FORM OF CLASS (PROGRAMS)
492 7 Write a Java program to print "Hello LJU" message using class LJ. 3
Write a Java program to find area and perimeter of a circle having radious=5
493 7 5
units using class Circle.
Write a Java program to count digits of an integer number given by user using
494 7 5
class.
Write a Java program to find product of all digits of an integer number given by
495 7 5
user using class
Write a Java program to check whether a given number given by user is
496 7 5
palindrome or not using class
Write a Java program to check whether a number given by user is Armstrong or
497 7 5
not using class
498 7 Write a Java program to find nPr by using class. (take n=10, r= 3) 4
TOPIC NAME:- DECLARING OBJECT AND CHARACTERISTICS OF OOPS, INSTANCE AND STATIC VARIABLES,
METHOD DECLARATION , CALLING AND SIGNATURE, CATEGORIES OF METHOD,SCOPE AND LIFETIME OF VARIABLES (MCQS)
what will be output of following code?
class student {
int rno;
String name;
void set() {
rno = 10;
name = "John"; }
void show() {
499 7 System.out.print(rno + " "); B 1 10 John 0 null 0 NULL Run time error
System.out.print(name); } }
class MainClass {
public static void main(String args[]) {
student s1 = new student();
student s2 = new student();
s1.set();
s2.show(); } }
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
what will be the output of following code?
class Circle {
double radius;
void set(double x) {
radius = x; }
void show() {
System.out.print(radius + " "); } }
500 7 class MainClass { C 1 5.1 6.1 0.0 0.0 Compile time error Run time error
public static void main(String args[]) {
Circle c1, c2 = new Circle();
c1.set(5.1);
c1.show();
c2.set(6.1);
c2.show(); }}
Given that Student is a class, how many reference variables and objects are
created by the following code?
Three reference Two reference One reference variable Three reference
Student studentName, studentId;
501 7 A 1 variables and two variables and two and two objects are variables and three
studentName = new Student();
objects are created. objects are created. created. objects are created.
Student stud_class = new Student();
What will be the output of the following Java program?
class box {
int width;
int height;
int length;
}
classname@hashcode
502 7 class mainclass { A 1 0 1 Runtime error
in hexadecimal form
public static void main(String args[]) {
box obj = new box();
System.out.println(obj.height);
}
}
503 7 Which of these operators is used to allocate memory for an object? C 1 malloc alloc new give
Which of the following is a valid declaration of an object of class Demo? Demo obj = new Demo obj = new
504 7 A 1 obj = new Demo(); new Demo obj;
Demo(); Demo;
Which of the following is invalid declaration of an object of class Demo? Demo d; Demo Demo = new
505 7 B 1 Demo d = new Demo(); Demo d = new Demo;
d = new Demo(); Demo();
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What will be the output of the program?
class Test {
public static void main(String[] args) {
Test p = new Test();
p.start(); }
void start() {
506 7 boolean b1 = false; D 1 true true true false false false false true
boolean b2 = fix(b1);
System.out.print(b1 + " " + b2); }
boolean fix(boolean b1) {
b1 = true;
return b1; }}
What will be the output of the following Java snippet, if compiled and executed
with command line “hello there” at runtime?
class Arg {
public static void main(String argv[]) {
String[] MyArg = argv;
507 7 } A 1 Compile time error hello there hello there
void amethod() {
System.out.println(argv[1]);
}
}
What will be the output of the following Java code?
class test {
int a, b;
void meth(int i, int j) {
i *= 2;
j /= 2; } }
class Output {
508 7 A 1 10 20 20 10 20 40 40 20
public static void main(String args[]) {
test obj = new test();
int a = 10;
int b = 20;
obj.meth(a, b);
System.out.println(a + " " + b); } }
What will be the output of below code?
class Student {
int id; // data member (also instance variable)
String name; // data member (also instance variable)
509 7 public static void main(String args[]) { B 1 00 0null nullnull idname
Student s1 = new Student();// creating an object of Student
System.out.print(s1.id);
System.out.print(s1.name);
}
}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What will be the output of below code?
class Let{
boolean status = true;
boolean grade = false;
public static void main(String[] args) {
boolean status = false;
boolean grade = true;
Let T = new Let();
510 7 T.check(T.grade == status); D 1 true FALSE TRUE false
System.out.print(status); }
void check(boolean status){
boolean run = true;
if (status == !grade){
return; }
else{
System.out.print(false); } } }
What is the output of the following Java code snippet?
class Test {
public static void main(String[] args) {
Student[] student = new Student[2];
student[0].name = "ABC";
student[0].marks = 'e';
student[0].section = 'A';
student[1].name = "DEF";
511 7 student[1].marks = student[0].marks; D 1 e e' 101 Runtime Error
student[1].section = student[0].section;
Student data = new Student();
data.print(student[1].marks); } }
class Student {
String name; int marks; char section;
void print(int a){
System.out.println(a); } }
What is the output of the Java code snippet?
class Test {
int a = 20, b, c;
void add(int a, int b) {
c = a + b;
System.out.print(a); }
void display() {
System.out.print(c);
512 7 System.out.print(a); } } B 1 101020 101320 100320 103010
class run {
public static void main(String[] args) {
Test ob = new Test();
ob.b = 10;
System.out.print(ob.b);
ob.add(1, 2);
ob.display(); } }
Which OOP concept allows a class to have more than one method with the same
513 7 A 1 Polymorphism Inheritance Abstraction Encapsulation
name but different implementations?
Which OOP principle promotes the idea of code reusability and the creation of
514 7 B 1 Polymorphism Inheritance Abstraction Encapsulation
class hierarchies in Java?
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
Which OOP concept shows a way to hide the internal details of an object and
515 7 C 1 Polymorphism Inheritance Abstraction Encapsulation
show only the necessary features?
Which OOP principle defines the concept of binding fields (object state) and
516 7 D 1 Polymorphism Inheritance Abstraction Encapsulation
methods (behavior) together as a single unit?
What will be the output of the following program?
class variable_scope {
public static void main(String args[]) {
int x;
x = 5;
{
517 7 A 1 Compile time error Runtime error 5656 565
int y = 6;
System.out.print(x + " " + y);
}
System.out.println(x + " " + y);
}}
The output of the following program is?
class Public {
int x = 10;
StringBuffer sb = new StringBuffer("Hello");
public static void main(String[] arg) {
int x;
518 7 Public p1 = new Public(); D 1 10 10 Hello 0 0 Hello Run time error Compile time error
System.out.print(x + " ");
p1.example(); }
void example() {
System.out.print(x + " ");
System.out.print(sb + " "); } }
What will be the output of the following code?
class P {
int a = 25;
void modify() {
int b;
b = a + 10;
}
519 7 } D 1 10 20 15 compile time error
class run {
public static void main(String[] args) {
P p1 = new P();
p1.a = 5;
System.out.println(p1.b);
}
}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the Java program ?
class P {
int vara=25;
void public change() {
System.out.println("hi"); }
}
520 7 class run { D 1 2510 2525 1010 Compile Error
public static void main(String[] args) {
P t6 = new P();
System.out.print(t6.vara);
t6.vara = 10;
System.out.println(t6.vara); } }
What is the output of the Java program ?
class P
{
int a=10,b=5;
521 7 void sum() B 1 Compile time error Run time error hi "hi"
{
System.out.println("hi");
}
}
What is the output of the Java program?
class equality {
int x, y;
boolean isequal() {
int x = 5, y = 6;
return (x == y); }
boolean isequal1() {
x++;
522 7 y++; A 1 false true true false false false true true
return (x == y); } }
class Output1 {
public static void main(String args[]) {
equality obj = new equality();
obj.x = 5; obj.y = 5;
System.out.print(obj.isequal() + " ");
System.out.print(obj.isequal1()); } }
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the Java program?
class Example {
boolean a;
double dd;
void setData(boolean a, double d) {
a = true;
523 7 dd = d; } B 1 true 5.0 false 5.0 0 5.0 5.0 false
void display() {
System.out.print(a + " " + dd); }
public static void main(String args[]) {
Example o = new Example();
o.setData(true, 5.0);
o.display(); }}
What is the output of the Java program?
class Call {
String m1(String a) {
a = "Welcome";
return a;
}
524 7 } B 1 Hello Welcome Hello Welcome Welcome Hello
class Main_Add {
public static void main(String[] args) {
Call a = new Call();
System.out.print(a.m1("Hello"));
}
}
What will be the output for following code?
class Test {
public static void main(String args[]) {
demo d = new demo();
d.change(); } }
525 7 class demo { D 1 This Example This mple This ample This xample
StringBuffer sb;
void change() {
sb = new StringBuffer("This is Example");
sb.delete(5, 9);
System.out.print(sb); } }
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the Java program?
class Test {
public static void main(String[] args) {
int out = 15;
Test T = new Test();
for (int i = 4; i < 6; i++) {
for (int j = 7; j >= 5; j--) {
if (i == j)
526 7 continue; A 1 100 25 87 67
if (i > j) {
out += T.method(i, j);
} else {
out += T.method(j, i); } } }
System.out.print(out); }
int method(int a, int b) {
if (a + b == 0) { return 2; }
return a + method(a - 1, b); } }
What is the output of the Java code snippet?
class Fruit {
void display (String a) {
System.out.println(a+" is yellow"); }
StringBuffer display (StringBuffer b) {
return (new StringBuffer(b+" is green")); } }
class Myprog { banana is green
banana is yellow banana is yellow banana is yellow
public static void main(String[] args) { banana is yellow
Fruit obj = new Fruit(); banana is green banana is green banana is green
527 7 A 1 banana
String s = "banana"; banana banana is yellow banana is green
banana is yellow
obj.display(s); banana is yellow banana is yellow banana is yellow
StringBuffer sb = new StringBuffer(s);
StringBuffer sb1 = new StringBuffer();
System.out.println(obj.display(sb));
sb1=obj.display(sb);
System.out.println(sb);
obj.display(s); } }
The output of the following program is?
class Main {
public static void main(String[] arg) {
Student s1 = new Student();
int b = 10;
int x = 11;
528 7 x = s1.printData(b); A 1 101020 101121 111223 101123
b = s1.printData(x);
System.out.print(x + b); } }
class Student {
int printData(int x) {
System.out.print(x);
return x++; } }
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the Java program ?
import java.util.*;
class Main {
public static void main(String[] arg) {
char a[] = { 97, 'a', 98, 'b', 99, 'c' };
Sorting s1 = new Sorting();
s1.tosort(a);
529 7 D 1 979798989999 999998989797 99c98b97a ccbbaa
for (int i = a.length; i > 0; i--) {
{
System.out.print(a[i - 1]); } } } }
class Sorting {
void tosort(char[] b) {
Arrays.sort(b); } }
530 7 What is the return type of a method that does not return any value? C 1 int float void double
From given options, choose the correct method name in java as per identifier
531 7 B 1 1seen $sum *get$ 2_run
concept.
What is the output of the Java code snippet?
class Output
{
char sum(int x) {
System.out.print(x);
return 'a';
532 7 } C 1 a 97 97a a97
public static void main(String args[]) {
Output t = new Output();
System.out.print(t.sum(97));
}
}
What is the output of the Java code snippet?
class Output {
char sum(int a) {
System.out.print(a);
return 'b';
}
533 7 C 1 b 98 97b a98
public static void main(String args[]) {
Output t = new Output();
System.out.print(t.sum(97));
}
}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the Java code snippet?
class Test
{
void show() {
System.out.print("\"SHOW Method\"");
return;
534 7 } C 1 SHOW Method SHOW method "SHOW Method" Compiler error
public static void main(String[] args) {
Test t2 = new Test();
t2.show();
}
}
What is the output of the Java code snippet?
class MyClass {
String Myclass() {
System.out.print("Zero");
return "One"; }
void myMethod() {
System.out.print("Two");
535 7 C 1 TwoZeroOneZero ZeroTwoZero TwoZeroZero TwoZeroOne
Myclass(); }}
class TestClass {
public static void main(String args[]) {
MyClass my = new MyClass();
my.myMethod();
my.Myclass(); }}
What is the output of the following Java code snippet?
class Argument {
public void tryPrimitives(int i, double f, char c, boolean test) {
i += 10;
c = 'z';
if (test)
test = false;
else
test = true; } ii = 1, ff = 1.0, cc = a, bb ii = 1, ff = 1.0, cc = 97, ii = 1.0, ff = 1.0, cc = a,
536 7 A 1 Error
public static void main(String args[]) { = false bb = true bb = false
Argument A = new Argument();
int ii = 1;
double ff = 1.0;
char cc = 'a';
boolean bb = false;
A.tryPrimitives(ii, ff, cc, bb);
System.out.println("ii = " + ii + ", ff = " + ff + ", cc = " + cc + ", bb = " + bb); }}
When invoking a method with an object argument, ___________ is passed. the object is copied,
the contents of the the reference of the
537 7 C 1 a copy of the object then the reference of
object object
the copied object
538 7 Which method can be defined only once in a program? A 1 main method finalize method static method private method
Return type is part of Method signature along with name and parameters list.
539 7 A 1 FALSE TRUE
True or False.
The variables declared in a class for the use of all methods of the class are called
540 7 C 1 reference variables objects instance variables None of the above
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the process of defining more than one method in a class differentiated
541 7 B 1 Function overriding Function overloading Function doubling None of the mentioned
by method signature?
542 7 Java method signature is a combination of ___. D 1 Return type
Method name Argument List B&C
543 7 In Java, a method name can not start with a ___. D 1 number hash (#) Hyphen (-) All the above
544 7 In Java, a method name can start with ___. D 1 Alphabet Underscore (_) Dollar ($) All the above
The main method should be static for the reason It can be accessed by
It can be accessed It can be executed
every method or
545 7 C 1 easily by the class without creating any None of the above
variable without any
loader. instance of the class.
hindrance.
TOPIC NAME:-METHOD DECLARATION , CALLING AND SIGNATURE, CATEGORIES OF METHOD (PROGRAMS)
Create a class name Temperature in which create methods of given name
546 7 ferenhit(), celcius() to perform basic conversion. Call all this methods using class 3
named Main.
Write a java program to access two variables and two methods with different
547 7 3
name using class.
Write a Java program to perform basic Calculator operations using following
methods catagories:
sum() - without arguments without return,
548 7 minus() - with arguments without return, 5
multi() - without arguments with return
divide() - with arguments with return
Design a class named Fan to represent a fan. The class contains:
- Three constants named SLOW, MEDIUM and FAST with values 1, 2 and 3 to denote the
fan speed. - An int data field named speed that specifies the speed of the fan (default
SLOW). - A boolean data field named f_on that specifies whether the fan is on (default
false). - A double data field named radius that specifies the radius of the fan (default 4). -
A data field named color that specifies the color of the fan (default blue).
- A no-arg method that creates a default fan.
- A parameterized method initializes the fan objects to given values.
549 7 - A method named display() will display description for the fan. If the fan is on, the 7
display() method displays speed, color and radius. If the fan is not on, the method returns
fan color and radius along with the message “fan is off”. Write a test program that
creates two Fan objects. One with default values and the other with medium speed,
radius 6, color brown, and turned on status true. Display the descriptions for two created
Fan objects.
Define the Rectangle class that contains:
Two double fields x and y that specify the center of the rectangle, the data field
width and height, A no-arg method that creates the default rectangle with (0,0)
for (x,y) and 1 for both width and height. A parameterized method creates a
rectangle with the specified x,y,height and width.
-A method getArea() that returns the area of the rectangle.
-A method getPerimeter() that returns the perimeter of the rectangle.
550 7 7
-A method contains(double x, double y) that returns true if the specified point
(x,y) is inside this rectangle. Write a test program that creates two rectangle
objects. One with default values and other with user specified values. Test all
the methods of the class for both the objects.
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
TOPIC NAME:- RECURSION (MCQS)
What is the output of the below Java program?
class test {
public static void main(String[] args) {
test rec = new test();
int sum = rec.summer(4);
System.out.println(sum);
}
551 7 int summer(int in) { A 1 10 6 0 Infinite loop
int sum = 0;
if (in == 0)
return 0;
sum = in + summer(--in);
return sum;
}
}
What is the output of the below Java program?
class Test3 {
public static void main(String[] args) {
Test3 rec = new Test3();
int sum = rec.summer(4);
System.out.println(sum);
}
552 7 int summer(int in) { A 1 11 10 4 16
int sum = 0;
if (in == 0)
return 1;
sum = in + summer(--in);
return sum;
}
}
What will be the output of following program?
class example {
void p() {
System.out.println("hello");
p(); hello will be printed
} few times and then it
Hello will be printed
553 7 C 1 hello will raise Compiler error
infinite times
public static void main(String[] args) { java.lang.StackOverflo
example rec = new example(); wError
rec.p();
}
}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What will be the output of following program?
class Rec {
int count = 0;
void p() { hello 0
hello 1 Hello 1
count++; hello 1
hello 2 Hello 2
if (count <= 5) { hello 2
554 7 A 1 hello 3 Hello 3 Compiler error
System.out.println("hello " + count); hello 3
hello 4 Hello 4
p(); } } hello 4
hello 5 Hello 5
public static void main(String[] args) { hello 5
Rec re = new Rec();
re.p(); } }
What will be output for following code?
class Test {
public static void main(String[] args) {
Test p = new Test();
p.start(); }
void start() {
boolean b1 = false;
555 7 boolean n2 = set(b1); A 1 false true true true true false FALSE TRUE
System.out.println(b1 + " " + n2); }
boolean set(boolean b1) {
if (b1 == false) {
b1 = true;
return set(b1);
} else
return b1; } }
What will be the output of the following program?
class Running {
public static void main(String[] args) {
run ob = new run();
int out = 15;
for (int i = 4; i < 6; i++) {
for (int j = 7; j >= 5; j--) {
if (i == j)
if (i > j)
556 7 out += ob.main(i, j); D 1 32 19 39 17
else
out += ob.main(j, i); } }
System.out.println(out); } }
class run {
int main(int a, int b) {
if (a - b == 0)
return 2;
return a - main(a - 1, b); } }
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What will be the output of the following program?
class Test {
public static void main(String[] args) {
run ob = new run();
int JA = 35;
int VA = 67;
557 7 int SUB = ob.method(JA, VA); C 1 Error 102 43 35
System.out.println(SUB); }}
class run {
int method(int ja, int va) {
if (ja % 13 == 0) {
return ja + va; }
return method(++ja, va / 2); } }
What is the output of the Java program?
class Javatest {
void rec(int n) {
if (n != 4)
return;
else {
System.out.print("TEST ");
558 7 C 1 JAVA TEST TEST TEST TEST TEST TEST JAVA TEST JAVA TEST JAVA
rec(n + 1);
System.out.print("JAVA "); } }
public static void main(String args[]) {
Javatest jt = new Javatest();
jt.rec(4); } }
What is the output of the Java program?
class Retest {
void rec(int n) {
if (n == 1)
return;
else {
559 7 System.out.print(n + 1 + " "); A 1 543012 555555 543210 012345
rec(--n);
System.out.print(n - 1 + " "); } }
public static void main(String args[]) {
Retest r = new Retest();
r.rec(4); } }
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output for the following code?
class NewTest {
int fact = 1;
void factorial(int n) {
if (n >= 4) {
System.out.println("Factorial of n = " + fact);
return;
560 7 } else { A 1 Factorial of n = 0 Factorial of n = 1 Factorial of n = 2 Factorial of n = 24
fact = fact * n;
factorial(n + 1); } } }
class Main {
public static void main(String[] arg) {
NewTest nt = new NewTest();
nt.factorial(0); } }
What is the output for the following code?
class Data {
int getData(int d) {
if (d == 0)
return 0;
else
return ((d % 2) + (10 * getData(d / 2)));
561 7 } D 1 1100 1011 1111 1010
}
class Main {
public static void main(String[] args) {
Data b = new Data();
System.out.println(b.getData(10));
}
}
What is the output of the Java code snippet?
class Test {
int i = 6;
void p() {
if (i < 0)
return;
System.out.print(--i + ",");
562 7 p(); C 1 Compile time error 5,4,3,2,1,0, 5,4,3,2,1,0,-1, 5432101
}
public static void main(String[] args) {
Test ob = new Test();
ob.p();
}
}
A function that calls itself for its processing is known as
563 7 D 1 Inline Function Nested Function Overloaded Function Recursive Function
564 7 Java uses ___ type of memory to implement Recursion. B 1 Heap Stack Register None
Java uses Stack type memory in implementing Recursion because of ___ feature
565 7 B 1 FIFO (First In First Out) LIFO (Last In First Out) Round Robin None
of STACK.
566 7 Recursion in Java applies to ___. C 1 Constructors Variables Methods Blocks
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
__________usually stops when the Java Runtime encounters an IF or ELSE
567 7 A 1 Recursion Stack objects class
statement with a RETURN statement
To end a recursive method a RETURN statement is usually kept inside ___.
568 7 C 1 IF block ELSE block IF or ELSE block None
Recursion in Java is a way of calling the method from within the same method.
569 7 A 1 TRUE FALSE
State TRUE or FALSE.
Which is the common problem with Recursive methods in Java? IndexOutOfBoundsExc
570 7 A 1 StackOverflowError OutOfMemoryError None
eption
TOPIC NAME:- RECURSION (PROGRAMS)
571 7 WAP to find HCF of two numbers using recursion. 3
572 7 Write a program to calculate factorial using recursion in Java 3
Write a Java program to calculate the power of a number like power(int
573 7 3
number, int power) like power(2, 3) should return 8.
Write a Java program to convert Decimal number to Binary number using
574 7 3
recursion.
Write a Java program to find GCD and LCM of two numbers using recursion
575 7 3
Write a Java program to print fibbonacci series upto n terms using recursion
576 7 3
Declare array numArr = {7,32,64,2,10,23}
Find smallest element in this array using Recursion.
577 7 Output format : Smallest element in the array is: 2 3
(no need to display given array, no need of any user input class like scanner)
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
UNIT 8- CLASS, OBJECT AND METHOD PART 2
TOPIC NAME:- METHOD OVERLOADING (MCQS)
578 8 Java method overloading implements the OOPS concept of_______. B 1 Inheritance Polymorphism Encapsulation None
Which is the overloaded static method of Math class to get absolute value in
579 8 D 1 Math.abs(int) Math.abs(float) Math.abs(double) All the above
Java?
What is process of defining two or more methods within same class that have
580 8 A 1 method overloading method overriding method hiding None of the mentioned
same name but different parameters declaration?
What is the output of the below Java program with multiple methods?
class MethodOverloading1
{
void show(int a, char b)
{
System.out.println("KING KONG");}
void show(char a, int b) {
System.out.println("JIM JAM"); JIM JAM KING KONG KING KONG
581 8 C 1 compiletime error
} JIM JAM KING KONG JIM JAM
public static void main(String[] args)
{
MethodOverloading1 m = new MethodOverloading1();
m.show(10, 'A');
m.show('B', 10);
}}
What is the output of the Java code snippet?
class Test {
void show(int a, char b) {
System.out.println("int char");
}
void show(char a, int b) {
System.out.println("char int"); }
582 8 void show(int a, int b) { B 1 97 98 Error 97 b int char
System.out.println(a + " " + b);
}
public static void main(String[] args) {
Test m = new Test();
m.show('a', 'b');
}}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the following given code?
class TestMCQ1 {
public static void main(String args[]) {
System.out.println("Hi Main String");
TestMCQ1 t1 = new TestMCQ1();
t1.main(10);
} Hi Main String Hi Main String
compile time error run time error
583 8 C 1 Hi Main float Hi Main int
public void main(int args) {
System.out.println("Hi Main int ");
}
public void main(float args) {
System.out.println("Hi Main float");
}}
What is the output of the following given code?
class TestMCQ2 {
void display(int a, char b) {
System.out.println("BYE BYE");
}
void display(char a, int b) {
System.out.println("Hi Hi"); Hi Hi
} BYE BYE BYE BYE compile time error
584 8 A 1 Hi Hi
Hi Hi BYE BYE
public static void main(String[] args) {
char A = 65;
TestMCQ2 m = new TestMCQ2();
m.display(10, 'A');
m.display(A, 10);
}
}
What is the output of the following given code?
class Test{
void display(int a, String b){
System.out.print("1"); }
void display(char a, StringBuffer b){
System.out.print("2"); }
void display(float a, float b){
585 8 System.out.print("3"); } D 1 123 331 321 113
public static void main(String[] args){
char A = 'a';
Test ob = new Test();
ob.display(1,"Bye");
ob.display('A',"Apple");
ob.display(10,10.0f); } }
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the following given code?
class Animal {
void display (String a) {
System.out.println(a+" is eating");}
StringBuffer display (StringBuffer b) {
return (new StringBuffer(b+" is sleeping"));}}
class Main_Animal{
public static void main(String[] args){ Monkey is eating Monkey is eating
Animal obj = new Animal(); Monkey is sleeping Monkey is eating Monkey is eating Monkey is sleeping
586 8 String s = "Monkey"; C 1 Monkey is sleeping Monkey is sleeping Monkey is sleeping Monkey is eating
obj.display(s); Monkey is eating Monkey is sleeping Monkey is eating Monkey is sleeping
StringBuffer sb = new StringBuffer(s);
System.out.println(obj.display(sb));
s= sb.toString();
obj.display(sb);
obj.display(s);
}
}
What is the output of the following given code?
class Add {
double add(int i, float f) {
return (i + f);
}
double add(float f, int i) {
return (f - i);
587 8 } B 1 -160.0 -34.0 -34 Compile Error
}
class Main_Add {
public static void main(String[] args) {
Add a = new Add();
System.out.println(a.add(10L, 'a') + new Add().add('A', -12f));
}
}
What is the output of the following given code?
class LJ {
void object(String i)
{
System.out.print("int ="+i);
}
void object(int s)
588 8 { B 1 String =s int =null int =0 Compile time error
System.out.print("String ="+s);
}
public static void main(String args[]) {
LJ method = new LJ();
method.object(null);
}}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the Java code ?
class Test{
public static void main(String s[]){
RUN utils = new RUN();
int x = utils.add(2, 8);
double y = utils.add(3.4, 6.6);
int z = utils.add(x, y, 20);
System.out.println("z = " + z);}}
class RUN{
589 8 int add(int i, int j) A 1 Error 40 40 10
{ return i + j; }
double add(double i, double j)
{ return i + j; }
double add(int i, double j, int k)
{ return i + j + k; }
double add(int i, double j, int k, double L)
{
return i + j + k + L;
}}
What is the output of the Java code ?
class LJ1{
String s;
long w ;
void method(double a , String b){
System.out.print("1");
}
590 8 void method(long a , StringBuffer s){ A 1 312 421 342 Compile time error
System.out.print("4");}}
class run{
public static void main(String args[]){
System.out.print("3");
LJ1 ob = new LJ1();
ob.method(ob.w,ob.s);
System.out.print("2");}}
What will be the output of the following program?
class MO{
public static void main(String[] args){
run ob = new run( );
int a = 12;
double b = 13;
double c = ob.m(a, b);
double d = ob.m(c, a);
double e = ob.m(a, (int) d);
System.out.println("c = " + c + " d = " + d + " e = " + e);
c = 25.0 d = 13.0 e =
591 8 }} B 1 Error c = 25.0 d = 13.0 e = 12 c = 25 d = 13 e = 12
12.0
class run{
double m(int x, double y){
return x + y;}
double m(double x, double y){
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r return x - y;}
double m(int x, int y){
return x % y;
}
}
What is the output of the Java code ?
class Add {
double add(int i, float f)
{ return ( i + f ); }
double add(float f, int i)
{ return ( f - i ); }
}
592 8 class run B 1 -34 -34.0 40 40
{
public static void main(String[] args){
Add a = new Add( );
System.out.println( a. add( 10L , 'a' ) + new Add().add( 'A' , -12f ) );
}
}
What is the output of the Java program?
class overload{
int x;
int y;
void add(int a){
x = y + 1 + a;}
void add(int a, int b){
593 8 x = x + 2 + b;}} B 1 5 16 8 6
class Overload_methods{
public static void main(String args[]){
overload obj = new overload();
int a = 0;
obj.add(5);
obj.add(4,8);
System.out.println(obj.x); }}
What is the output of the Java program?
class TestNum{
int a,b;
void print(int a, float b){
a = a + (int)b;}
void print(TestNum t){
a = t.a * t.b;}}
594 8 A 1 0 20 200 30
class TestNumMain{
public static void main(String args[]){
TestNum t1 = new TestNum();
TestNum t2 = new TestNum();
t1.print(10,20);
t1.print(t2);
System.out.println(t2.a);}}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the Java program?
class TestString{
void show(String a){
a = a + "Hi";
System.out.println(a);
}
void show(Object a){
595 8 a = a + "Bye"; D 1 null Hi Bye nullHi
System.out.println(a);
}}
class TestStringMain{
public static void main(String args[]){
TestString t1 = new TestString();
t1.show(null);
}}
What is the output of the Java program?
class Overload
{
void display (int a, double d)
{
System.out.print(a+d); }
double display (int aa, double dd){
596 8 return(aa+dd); } A 1 Compile time error 99 9.5 9.5 9 9.5
public static void main(String args[])
{
Overload o = new Overload();
o.display(4,5.0);
System.out.print(o.display(4,5.5));
}
}
What will be the output for the following?
class MyAbs{
int abs(int a){
return a<0?-a:a;}
float abs(float b){
return b<0?-b:b;}
double abs(double c){
597 8 return c<0?-c:c;} D 1 10, 4.56, 10.123 -10, -4.56, -10.123 10, -4.56, -10.123 Error
public static void main(String[] args){
MyAbs m =new MyAbs();
int a=-10;
float b=-4.56f;
double c=-10.123;
System.out.println(m.abs(a) + ", " + MyAbs.abs(b) + ", " + MyAbs.abs(c));
}}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output for following code?
class Demo{
public static void main(String args[]) {
byte Int=2;
Run d=new Run();
System.out.println(d.m1(null));}}
class Run{
int m1(String i){
598 8 return m1(5);} B 1 Run time Error 120 5 5
int m1(int s){
if(s==0)
return 1;
return s*m1(s-1);}
int m1(short s){
if(s==0)
return 1;
return s*m1(s-1);}}
What is the output of the following Java code snippet?
class Test{
public static void main(String[] args) {
Test T = new Test();
char ch[] = new char[]{'A','B','C','D'};
T.method(ch);
T.method(ch[2]);
System.out.println(ch[2]);
599 8 } C 1 1 2 3 Error
void method(char ch){
ch += 'a';
}
void method(char[] s){
String ch = "1234";
for(int i=0;i<s.length;i++){
s[i] = ch.charAt(i);
}}}
What is the output of the following Java code snippet?
class Test{
public static void main(String[] args) {
Test T = new Test();
System.out.print(T.methodOne(10.2f,'a'));
T.methodOne(5,10.2);
System.out.print(T.methodOne('A',10.2f));
System.out.println(T.methodOne('A',10));}
600 8 A 1 Error 9715.275.2 9715.275.210 275.9715
float methodOne(int i, float f){
return i+f;}
float methodOne(float i, float f){
return i+f;}
void methodOne(float f, double d){
System.out.print(f+d);}
int methodOne(float f, int i){
return i; }}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output for the following code?
class Main2{
public static void main(String[] arg) {
Main2 m[] = new Main2[3];
for(int i=0; i<m.length; i++) {
m[i] = new Main2(); }
m[1].main(12.5); m[2].main(12.0f); m[3].main(12L);}
long main(int i) {
601 8 System.out.print(i+" "); B 1 12.5 12.5 12.5 Run time error Compile time error 12.5 12.0 12.0
return 0L; }
void main(float f) {
System.out.println(f+" ");}
int main(double d) {
System.out.print(d+" ");
return 1;
}
}
What is the output for the following code?
class XYZ {
public static void main(String[] arg) {
Student s1 = new Student();
String sb = new String("Hii");
s1.printData(s1);
s1.printData(sb);
602 8 C 1 Hii Hello Hello LJU Hii Hello LJU Compile time error Run time error
System.out.print(s1.printData(null));} }
class Student {
void printData(Student s) {
System.out.print("Hii ");}
String printData(String sb) {
System.out.print("Hello ");
return "LJU";} }
TOPIC NAME:- METHOD OVERLOADING (PROGRAMS)
Write a program which asks user to choose one option to find area using
method overloading.
1. To calculate area of circle
603 8 2. To calculate area of rectangle 5
3. To calculate area of triangle
Methods to find area of circle,area of rectangle & area of triangle should be
named as "area".
Create a program that implements a calculator with overloaded methods for
addition, subtraction, multiplication, and division.
604 8 The calculator should have methods like calculate(int a, int b), calculate(double 5
a, double b), and so on to perform the respective operations based on the data
types of the input parameters.
Create a class comparison which has compare() method which compare two
605 8 5
integer value, character value and double value using method overloading
TOPIC NAME:- ACTUAL AND FORMAL ARGUMENTS (MCQS)
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the following given code?
class overload {
int x;
int y;
void add(int a) {
x = a + 1;}
void add(int a, int b){
606 8 x = a + 2;} } C 1 5 6 7 8
class Argument {
public static void main(String args[]) {
overload obj = new overload();
int a = 0;
obj.add(6);
System.out.println(obj.x);
}}
What is the output of the following given code?
class Argument {
public void tryPrimitives(int a, int b){
int temp;
temp = a;
a = b;
b = temp;
607 8 } B 1 a = 12 b = 11 a = 11 b = 12 a = 11 b = 11 a = 12 b = 12
public static void main(String args[]) {
Argument A = new Argument();
int a = 11;
int b = 12;
A.tryPrimitives(a,b);
System.out.println("a = " + a + " b = " + b);
} }
What is the output of the following given code?
class Argument {
public void tryPrimitives(int i, double f, char c, boolean test){
i += 10;
c = 'z';
if(test) test = false;
else test = true;}
ii = 1, ff = 1.0, cc = a, bb ii = 1, ff = 1.0, cc = a, bb ii = 1, ff = 1.0, cc = z, bb ii = 11, ff = 1.0, cc = a,
608 8 public static void main(String args[]) { A 1
= false = true = false bb = false
Argument A = new Argument();
int ii = 1;
double ff = 1.0;
char cc = 'a';
boolean bb = false;
A.tryPrimitives(ii, ff, cc, bb);
System.out.println("ii = " + ii + ", ff = " + ff +", cc = " + cc + ", bb = " + bb); } }
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the following given code?
class Argument {
public int tryPrimitives(int x, int y) {
x = x + 10;
y = y + 10;
return x;
}public static void main(String args[]) {
609 8 Argument A = new Argument(); B 1 10 11 5 20
int p = 1;
int q = 2;
int r = 5;
r = A.tryPrimitives(p, q);
System.out.println(r);
}
}
TOPIC NAME:- PASSING ARRAYS TO METHOD, ARRAY OF OBJECTS (MCQS)
What is the output of the below Java program?
class GFG {
void function1(int[] array) {
System.out.println("The first element is: " + array[0]);
}
public static void main(String[] args) {
// creating instance of class
610 8 A 1 The first element is: 1 The first element is: 2 The first element is: 3 The first element is: 5
GFG obj = new GFG();
// creating a 1D and a 2D array
int[] oneDimensionalArray = { 1, 2, 3, 4, 5 };
// passing the 1D array to function 1
obj.function1(oneDimensionalArray);
}}
What is the output of the Java program?
class GFG{
int f(int a[],int i, int n){
if(n <= 0)
return 0;
else if(a[i] % 2 == 0)
return a[i] + f(a, i+1, n-1);
611 8 else C 1 -9 5 15 -15
return a[i] - f(a, i+1, n-1);
}
public static void main(String args[]){
GFG g = new GFG();
int a[] = {12, 7, 13, 4, 11, 6};
System.out.print(g.f(a,0,6));
}}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the below Java program?
class Main{
public static void addTen(int[] arr)
{
for(int i = 0; i < arr.length; i++) {
arr[i] += 10;}
}
612 8 public static void main(String[] args) C 1 13579 10 30 50 70 90 11 13 15 17 19 10 3 5 7 9
{
int[] arr = {1, 3, 5, 7, 9};
addTen(arr);//Simply pass the name of the array to the method
for(int i = 0; i < arr.length; i++)
{
System.out.print(arr[i] + " ");
}}}
What is the output of the following code?
class Main1{ int count=0,i;
int countNeg(int []a){
for(i=0;i<a.length;i++){
if(a[i]<0) count++;}
return i;
613 8 } C 1 2 3 5 0
public sta c void main(String args[]){
int x[]={-1,3,5,7,-9};
Main1 c1=new Main1();
System.out.println(c1.countNeg(x));
}
}
What is the output of the following code?
class Main{
void methodArr(double []arr,double x,double y){
for(int i=0;i<arr.length;i++){
if(arr[i]==x) {arr[i]=y;}}
}
public static void main(String a[]){ 0.0 12.0 22.0 0.0 20.0 2.0 12.0 22.0 0.0 20.0
614 8 B 1 0 12 22 0 20 200 Compile error
double arr[]={2,12,22,2,20,200}; 200.0 200.0
Main m1=new Main();
m1.methodArr(arr,2,0);
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+" ");}
}
}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the Java code snippet?
class New{
public static void main(String args[ ]) {
New n = new New();
int arr[] = {10, 30, 30, 60};
System.out.println(n.guess(arr));
}
615 8 C 1 30 32 32.5 17.5
double guess(int[] arr) {
double output = 0;
for (int i = 0; i < arr.length; i++)
output = output + arr[i];
return output / arr.length;
}
}
What will be the output of the following code?
class Test{
void multAll(int []a, int amt){
int i = 0;
while (i < a.length){
a[i] = a[i] * amt;
616 8 D 1 -15 9 -6 Error
i++;}}
public static void main(String [] args){
int[ ] a = {1, 3, -5, -2};
Test t1 = new Test();
t1.multAll(a,3);
System.out.println(t1.a[2]);}}
What is the output of the Java program?
class Arrays
{
void arr(int a[])
{
for(int i=0;i<3;i++)
{
617 8 a[i]=a[i+1]*3; C 1 123 234 6 9 12 666
System.out.print(a[i]+" ");
}}
public static void main(String args[])
{
Arrays r = new Arrays();
int a[] = {1,2,3,4};
r.arr(a); }}
A copy of the first The reference of the
618 8 When you pass an array to a method, the method receives ________ . C 1 A copy of the array. The length of the array.
element. array.
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
what will be output of following code
class student {
int rno;
char ch;
void set() {
rno = 5;
ch = 'A';}
void show() {
619 8 System.out.print(rno + " "); D 1 5A 0 null 00 Run Time Error
System.out.print((int) ch);
}
}
class MainClass {
public static void main(String args[]) {
student s[] = new student[5];
s[0].set();
s[0].show();
}
}
What is the output of the following code?
class Main1
{
int count=0,i;
int countNeg(int []a){
for(i=0;i<a.length;i++)
{
620 8 if(a[i]<0) D 1 2 7 -9 5
count++;}
return i; }
public static void main(String args[])
{ int x[]={-1,3,5,7,-9};
Main1 c1=new Main1();
System.out.println(c1.countNeg(x));
}}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the following code?
class Main{
public void addTen(int[] arr){
for(int i = 0; i < arr.length; i++){
arr[i] += 10;}}
public static void main(String[] args)
{
621 8 int[] arr = {1, 3, 5, 7, 9}; A 0.5 11 13 15 17 19 13579 97531 19 17 15 13 11
Main obj = new Main();
obj.addTen(arr);
for(int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}}
TOPIC NAME:- PASSING ARRAYS TO METHOD, ARRAY OF OBJECTS (PROGRAMS)
622 8 Write a Java program to create an array of objects 5
Create a class Student with Roll_No ,Name and Mobile_No as data member. Use
623 8 necessary method to initialize it and to print. Create at least 5 student. (Use 3
array of object).
Write a Java Program to Create a class Account. It has three data member
account id, name and balance.
Define method to assign value and display value. Define method that search
624 8 7
account number given by the user. If account number exists, print detail of that
account. Write a program using array of object. Declare at least 5 account and
print details.
Write a Java program to sort the numbers by using the concept of passing arrays
625 8 5
to methods
Write a Java program to display elements of one dimensional array using
626 8 5
passing arrays to methods
Write a Java program to find Even number and Odd number from given Array
627 8 5
using the concept of passing arrays to methods
Write a java program to find min and max values from a given array using
628 8 5
passing arrays to methods.
Write a java program to reverse elements of array using logic of swapping
629 8 elements. Here, use concept of passing array as argument to method. method. 5
Use Scanner class to enter Array elements.
TOPIC NAME:- CALL BY VALUE AND CALL BY REFERENCE (MCQS)
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the following given code?
class CallbyValue {
byte change(byte b) {
++b;
return b; }}
class Main{
Value of a after "Value of a after Value of a after "Value of a after
public sta c void main(String[] args) {
passing: 128 passing: -128 passing: -128 passing: -128
630 8 C 1
Value of x after Value of x after Value of x after Value of x after
CallbyValue obj = new CallbyValue();
modifying: 129 modifying: 129 modifying: -127 modifying: 127
byte a = (byte)128;
byte x = obj.change(a);
System.out.println("Value of a a er passing: " +a);
System.out.println("Value of x a er modifying: " +x);
}}
What is the output of the Java code snippet?
class CallbyValue
{
int x = 20;
void modify(int x)
{
x = x + 200; Value of x after Value of x after Value of x after Value of x after
631 8 System.out.println("Value of x after modification: " +x); D 1 modification: 220 modification: 200 modification: 0 modification: 220
} Original value of x: 0 Original value of x: 20 Original value of x: 20 Original value of x: 20
public static void main(String[] args)
{
CallbyValue t = new CallbyValue();
t.modify(t.x);
System.out.println("Original value of x: " +t.x); } }
What is the output of the Java code snippet?
class Animal{
int a;
void display(Animal a1) {
a=20;
a=a1.a;}
void setA(int a1){
632 8 a=a1;}} A 1 300 20 Compile time error Run time error
class Test3 {
public static void main(String args[]) {
Animal a1 = new Animal();
Animal a2 = new Animal();
a1.setA(300);
a2.display(a1);
System.out.println(a2.a);}}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output of the Java code snippet?
class Bird {
int a;
void display(Bird a1) {
a = 20; }
void setA(int a1) {
a = a1; } }
633 8 class TestMCQ4 { B 1 300 20 Compile time error Run time error
public static void main(String args[]) {
Bird a1 = new Bird();
Bird a2 = new Bird();
a1.setA(300);
a2.display(a1);
System.out.println(a2.a); } }
When you invoke a method with a parameter, the value of the argument is
634 8 passed to theparameter. This is referred to as _________ B 0.5 method invocation pass by value pass by reference pass by name
What is the output of the Java code snippet?
class GoodLuck {
int posts=10;
}
class Java {
public static void main(String[] args)
{
635 8 GoodLuck wp1 = new GoodLuck(); D 1 1010 2030 3010 3030
wp1.posts = 20;
GoodLuck wp2 = wp1;
wp1.posts = 30;
System.out.print(wp1.posts);
System.out.print((wp2.posts));
}
}
TOPIC NAME:- CALL BY VALUE AND CALL BY REFERENCE (PROGRAMS)
Write a Java program to find sum of n numbers by using the concept of call by
636 8 3
value
Write a Java program to add 5 in original value of array elements and display
637 8 3
modified elements of one dimensional array using pass by value mechanism.
Write a Java program to change original value,which is given from user by using
638 8 3
appropriate Parameter passing technique.
Write a Java program to Swap two values,which is given from user by using call
639 8 3
by value.
Write a Java program to Swap two values,which is given from user by using call
640 8 3
by reference.
Write a program using call by reference concept to read an array of integers and
641 8 3
print its elements in reverse order
Write a Java program to copy one array into another array using call by
642 8 3
referrence
TOPIC NAME:- Returning object, Object as Parameter (MCQS)
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output for the following code?
class Add{
int a;
int b;
void sum(Add A1){
int sum1=A1.a+A1.b;
System.out.println("Sum of a and b :"+sum1);}}
643 8 class classExAdd{ C 1 error Sum of a and b :0 Sum of a and b :30 none of these
public static void main(String arg[]){
Add A=new Add();
A.a=10;
A.b=20;
A.sum(A);
}
}
What is the output for the following code?
class Add {
int a;
int b;
Add sum(Add A1) {
int sum1 = A1.a + A1.b;
return A1;
644 8 }} B 1 30 classname@hashcode 10 error
class classExAdd {
public static void main(String arg[]) {
Add A = new Add();
A.a = 10;
A.b = 20;
System.out.println(A.sum(A)); }
}
What is the output of the Java code snippet?
class Time{
int hour, min;
public static void main(String[] args) {
Time t3= new Time();
Time t2= new Time();
t3.input(1,20);
645 8 t3.sum(t3,t2); } C 1 0 20 0 20 1 0 1 20 0 20 1 20 0000
void input(int h,int m){
hour=h;
min=m;}
void sum(Time t2,Time t3){
min= t3.min+t2.min;
hour = t3.hour+t2.hour;
System.out.print(t3.hour+" "+t2.min+" "+hour+" "+min);}}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
What is the output for following code?
class Test{
int a, b;
void meth(Test o){
if(o.a>100){
o.a = o.a * 2;
o.b = o.b / 2;}
else{
646 8 o.a=o.a+2; A 1 obj.a = 2 obj.b = -2 obj.a = 300 obj.b = 100 obj.a = 152 obj.b = 198 Compiletime Error
o.b=o.b-2;}}}
class JavaProgram{
public static void main(String args[]){
Test obj = new Test();
int a = 150, b = 200;
obj.meth(obj);
System.out.println("obj.a = " + obj.a + " obj.b = " + obj.b);}}
What is stored in variable d for below code?
class conversion
{
float a = 295.04f;
int b = 300;
public static void main(String args[])
{
647 8 conversion c=new conversion(); D 1 339.4f 339 0.4 339.04
c.change(c);
}
void change(conversion c1)
{
float d = c1.a + (byte) c1.b;
System.out.println(d);
}}
What is the output for the following code?
class Salmon {
int count;
void salmon1(salmon1 s) {
s.count = 4;
return s;}
648 8 C 1 4 1 Error classname@hashcode
public static void main(String[] args) {
Salmon s1= new Salmon;
Salmon s2= new Salmon;
s2=s1.salmon1(s1);
System.out.println(s2.count);
}}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
what is the output for the above code?
class B {
int i,j;
void display(B obj1) {
System.out.println(obj1.i+" "+obj1.j);
}
public static void main(String args[]) {
649 8 A 0.5 12 12 1 2
B obj = new B();
obj.i=1;
obj.j=2;
obj.display(obj);
}
}
What is the output of the below Java program?
class Operation2{
int data=50;
void change(Operation2 op){
op.data=op.data+100;
}
before change 50 before change 50 before change 100 before change 150
650 8 public static void main(String args[]){ A 1
after change 150 after change 100 after change 150 after change 50
Operation2 op=new Operation2();
System.out.println("before change "+op.data);
op.change(op);//passing object
System.out.println("after change "+op.data);
}}
What is the output of the Java program?
class Test {
int a;
int b;
void set(int i, int j) {
a = i;
b = j;
}
void meth(Test o) {
o.a *= 2;
651 8 o.b /= 2; B 1 48 84 49 94
}
}
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
class Output {
public static void main(String args[]) {
Test obj = new Test();
obj.set(4, 9);
obj.meth(obj);
System.out.println(obj.a + " " + obj.b);
}
}
What is the output of the following Java code snippet?
class Test{
int var1, var2;
public static void main(String[] args) {
Test T1 = new Test();
Test T2 = new Test();
T1.var1 = 12; T1.var2 = 120;
T2.var2 = 60; T2.var1 = 100;
Test T3 = new Test();
T3.run(T1,T2);
652 8 System.out.print(T3.var2);} D 1 5 1 555 515
Test run(Test p1, Test p2){
var1 = p1.var2 / p2.var1;
var2 = p2.var2 / p1.var1;
Test obj = new Test();
obj.var1 += var2;
System.out.print(obj.var1);
obj.var2 += var1;
System.out.print(obj.var2);
return obj;
}}
void functionName ( ){ object functionName( ) class object ClassName
653 8 Which is the correct syntax for returning an object ? D 0.5
} {} functionName( ) { } functionName ( ){ }
654 8 How many independent objects can be returned at same time from a method? A 0.5 1 2 3 4
655 8 How many objects can be passed to a method simultaneously? D 0.5 Only 1 Only an array Only 1 or an array As many as required
TOPIC NAME:- Returning object, Object as Parameter (PROGRAMS)
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r
1. Program Objective:
The program's primary goal is to calculate the sum of two distances (in
kilometers and meters) and display the result in a user-readable format.
2. Classes and Methods:
- `Distance` class:
- `int km, m`: Instance variables to store kilometers and meters.
- `Scanner sc`: Used to take input from the user.
- `void get()`: Method to input distance values from the user.
- `void show(int a, int b)`: Method to display the distance in kilometers and
meters.
- `Distance add(Distance obj1, Distance obj2)`: Method to add two distances
and return the result as a new `Distance` object.
- `run` class:
- `main(String args[])`: The main method where the program execution
656 8 7
begins.
- Creates instances of the `Distance` class, takes input for two distances,
calculates their sum, and displays the result.
3. Input and Output:
- The program prompts the user to input two distances: one in kilometers and
another in meters (or 0 if no meters are present).
- After input, it calculates the sum and displays it in kilometers and meters.
4. Distance Calculation:
- The `add` method of the `Distance` class takes two `Distance` objects, adds
their kilometer and meter values, and handles the carryover from meters to
kilometers when necessary.
5. Output Format:
- The program displays the sum of distances in the format "Distance = X.Y KM,"
where X is kilometers, and Y is meters.
The provided Java code represents a program that deals with time calculations
using a `Time` class. Here's a problem definition for this code:
1. Program Objective:
The program's primary goal is to manipulate and display time values in terms
of hours and minutes.
2. Classes and Methods:
- `Time` class:
- `int hr, min`: Instance variables to store hours and minutes.
- `void Set(int x, int y)`: Method to set the time using provided hour and
minute values.
- `void Set(Time obj1, Time obj2)`: Method to set the time by adding the
hours and minutes from two `Time` objects.
- `void show()`: Method to display the time in hours and minutes and handle
657 8 the conversion of excess minutes to hours if necessary. 7
- `TestA` class:
- `main(String args[])`: The main method where program execution begins.
L.J Institute of Engineering and Technology, Ahmedabad.
Note : This question bank is only for reference purpose. LJU Test question paper may not be completely set from this question bank.
Unit
Sr
Numbe Question_Text MCQ Answer Marks Option A Option B Option C Option D
No
r - `main(String args[])`: The main method where program execution begins.
- Creates instances of the `Time` class, sets time values, adds them, and
displays the result.
3. Time Manipulation:
- The `Time` class allows setting time using either direct hour and minute
values or by adding the hours and minutes from two `Time` objects.
4. Output Format:
- The program displays the time in hours and minutes in the format "hr=X" and
"min=Y," where X and Y represent the hour and minute values, respectively.
Declare a class called coordinate to represent 3 dimensional Cartesian
coordinates(x, y, and z) define following method.
- Initialize Method
658 8 - Display method to print values of members 7
- Add_coordinates method, to add three such coordinates object to produce a
resultant coordinates object.
- Main , to show use of above method
Write a Java program to find the power of number using passing an object to the
659 8 method(i.e num=5 and power=3 then ans is5^3 that is 125) 5
Write a Java program to find GCD of two numbers using passing an object to the
660 8 5
method(i.e a=4 and b=6 then GCD is 2)