0% found this document useful (0 votes)
88 views10 pages

Reduce Complexity Single Interface For General Class of Actions

This document contains a summary of a question bank for an Advanced Java exam. It includes 15 multiple choice questions about Java concepts like encapsulation, inheritance, polymorphism, data types, loops, and control flow statements. The questions cover topics like access modifiers, operator precedence, break and continue statements, nested loops, and more. Correct answers or explanations are provided for each question.

Uploaded by

Geetik Narula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views10 pages

Reduce Complexity Single Interface For General Class of Actions

This document contains a summary of a question bank for an Advanced Java exam. It includes 15 multiple choice questions about Java concepts like encapsulation, inheritance, polymorphism, data types, loops, and control flow statements. The questions cover topics like access modifiers, operator precedence, break and continue statements, nested loops, and more. Correct answers or explanations are provided for each question.

Uploaded by

Geetik Narula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

ID No. ……………….. Total No.

of Pages:00
Question Bank
BCA-VI Semester
CAL4316-Advanced Java
Department: BCA
Note: Each question carries one mark.

1. Which statementdefines the functionality of 5. Judge and mark the correct output of the code.
‘Encapsulation’? class comma_operator
A. Binding of code and C. Reduce Complexity {
data together public static void main(String args[])
B. Using single D. All of the mentioned {
interface for general int sum = 0;
class of actions. for (inti = 2, j = 3; i< 10 & j < 10; ++i, j = i
+ 1)
2. The phrase, ‘One interface, multiple methods’ sum += i;
defines which concept? System.out.println(sum);
A. Abstraction C. Polymorphism }
B. Inheritance D. Encapsulation }
A. 26 C. 35
3. What is the output of this program? B. 36 D. compilation error
class Test { Explanation: Using comma operator, we can include
int a; more than one statement in the initialization and
public int b; iteration portion of the for loop. Therefore both ++i
private int c; and j = i + 1 is executed i gets the value – 2,3,4,5,6,7,8
} & j gets the values 3,4,5,6,7,8,9. And sum=
class example_questionbank { 2,5,9,14,20,27,35.
public static void main(String args[])
{ 6. After compiling the below code, Whatwill be
Test ob = new Test(); displayed in Line 14?
ob.a = 10; class jump_statments
ob.b = 20; {
ob.c = 30; public static void main(String args[])
System.out.println(" Output :a, b, and c" + ob.a {
+ " " + ob.b + " " + ob.c); int x = 2;
} int y = 0;
} for ( ; y < 10; ++y)
A. Compilation error C. Run time error {
B. Output : a, b and c 10 D. Exception if (y % x == 0)
20 30 continue;
Explanation: c has private access in Test else if (y == 8)
break;
4. Pick up the correct range of byte data type in else
Java? System.out.print(y + " ");//Line 14
A. -128 to 127 C. -32768 to 32767 }
B. -2147483648 to D. 1 to 128 }
2147483647 }
Explanation: Byte occupies 8 bits in memory. Its range A. 1 3 5 7 C. 2 4 6 8
is from -128 to 127. B. 1 3 5 7 9 D. 1 2 3 4 5 6 7 8 9
Explanation: Whenever y is divisible by x remainder
body of loop is skipped by continue statement,
therefore if condition y == 8 is never true as when y is 11. What will happen when you attempt to compile
8, remainder body of loop is skipped by continue and run the following code?
statements of first if. Control comes to print statement class Question_Bank
only in cases when y is odd. {
public static void main(String ar[]){
7. Which of the following statement is correct? inti=0;
A. For positive C. Java provides two while(i>0)
numbers, result of operators to do {
operators >> and left shift <<< and System.out.println("Value of i: "+i);
>>> are same <<
}
B. >> is the zero fill D. >>> is the signed do{
right shift operator right shift operator System.out.println(i);
} while (i<2);
}}
8. Define byte code in the context of Java? A. Value of i: 0 followed C. 012
A. The type of code C. The type of code by 0 1 2
generated by a Java generated by a Java B. Value of i: 0 D. Continuous output
compiler2 Virtual Machine Followed by of 0
B. It is another name D. It is the code written continuous output
for a Java source file within the instance of 0
methods of a class.
12. class Question_Bank
9. A top level class cannot have following access {
modifiers. public static void main(String arg[]){
I. protected, private inti;
II. public, protected int j;
III. private, public outer:
IV. public, default for (i=1;i<3;i++)
Only I C. Only IV inner:
Both I and III D. I , II and III for(j=1; j<3; j++) {
10. What gets printed when the following program if (j==2)
is compiled and run? Select the one correct continue outer;
answer. System.out.println("Value for i=" + i + " Value
class Question_Bank { for j=" +j);
}
public static void main(String args[]) { }
inti,j,k; }
for (i = 0; i< 3; i++) { (i) Value for i=1 value for j=1
for(j=1; j < 4; j++) { (ii) Value for i=2 value for j=1
for(k=2; k<5; k++) { (iii) Value for i=2 value for j=2
if((i == j) && (j==k)) (ivIValue for i=3 value for j=1
System.out.println(i);
} A. Both (i) and (ii) C. Only (i)
} B. Only (iii) D. Either (i) or (ii)
}
} 13. What will happen when you attempt to compile
} and run the following code in a method?
A. 0 C. 1 for(inti=0;i<5;){
B. 2 D. 3 System.out.println(i);
i++;
continue;
}
A. Compile time error, C. Compile time error 15. What will happen when you attempt to compile
malformed for continue within for and run the following code?
statement loop public class LabLoop{
B. runtime error D. compile and run public static void main(String argv[]){
continue statement with output 0 to 4 LabLoop ml = new LabLoop();
not reached ml.amethod();
mainmethod:
14. class Question_Bank System.out.println("Continuing");
{ }
public static void main(String argv[]){ public void amethod(){
Question_Bankqb= new Question_Bank(); outer:
qb.switch_method(); for(inti=0;i<2;i++){
} for(int j=0;j<3;j++){
if(j>1)
public void switch_method(){ break mainmethod;
char k=10; System.out.println("i "+ i + " j "+j);
switch(k){ } }//End of outer for
default: }}
System.out.println("This is the default output"); A. i 0 j 0 C. i 0 j 0
break; i0j1 i0j1
case 10: Continuing i1j0
System.out.println("ten"); i1j1
break; Continuing
case 20: B. Compile time error D. i 0 j 0
System.out.println("twenty"); i0j1
break; i1j0
} i1j1
} i2j1
} Continuing
A. None of these C. Compile time error
options target of switch 16. Given a one dimensional array arr, what is the
must be an integral correct way of getting the number of elements
type in arr. Select the one correct answer.
B. Compile and run D. Compile and run A. arr.length C. arr.size
with output "This is with output "ten“ B. arr.length - 1 D. arr.size - 1
the default output"
17. Which of these statements are legal. Select the
three correct answers.
A. intarr[][] = new C. int[][] arr = new
int[5][5]; int[5][5];
B. int []arr[] = new D. int[] arr = new
int[5][5]; int[5][];
18. What will be the output of the following
program ? 24. Identify the statement that correctly defines a
class Question { feature of constructor.
static inti=1,j=2; A. All classes must C. A constructor can
static { define a constructor declare a return
display(i); value
} B. A constructor can be D. A constructor must
public sttaic void main(String ar[]) declared private initialize all the
{ member variables of
display(j); a class
}
static void display(int n) 25. What will the result of compiling and executing
{ the following program. Select the one correct
System.out.println(n); answer.
} class Test {
} public static void main (String args[]) {
intarr[] = new int [2];
A. 1 C. 2 System.out.println(arr[0]); } }
B. 12 D. 21
A. The program does C. The program
19. Identify the true statement. not compile because generates a runtime
A. A top-level class may C. A constructor may arr[0] is being read exception because
be declared as be declared as before being arr[0] is being read
private volatile initialized. before being
B. A method may be D. A local variable may initialized.
declared as transient be declared as final B. The program D. The program
compiles and prints compiles and prints
20. Choose the statement that correctly describe 0 when executed 1 when executed
the use of access modifiers within a class.
A. They can be applied C. They must follow 26. What happens when the following program is
to both data and class’s data variables compiled and then the command –
method or methods "java check it out" is executed.
B. They must precede D. They can appear in Select one correct answer.
class’s data any order class check {
variables or public static void main(String args[]) {
methods System.out.println(args[args.length-2]);
21. The this reference is used in conjunction with--- }
-------method }
A. static C. All A. The program does C. The program
B. non-static D. None of the above not compile. compiles but
generates
22. Which of the following are legal declarations? ArrayIndexOutOfBo
A. public protected C. public void amethod undsException
amethod (inti) (void) exception.
B. public void D. void public amethod B. The program prints D. The program prints
amethod (inti) (inti) it java

23. String s = new String("xyz"); 27. Which of the following declare an array of String
Assuming the above declaration, which of the objects ?
following statements would compile. A. String[] s; C. String [] s[];
A. s = 2 * s; C. s = s + s; B. String [20] s; D. String s[20];
B. inti = s[0]; D. s = s >> 2;
28. Cite the error in the following program. 31. What would be the result of attempting to
class question { compile and run the following program ?
String s=“abc”; class Myclass {
public static void main(String[] ar) static Myclass ref;
{ String[] arguments;
System.out.println(s); public static void main(String ar[]) { ref=new
} } Myclass();
ref.func(ar); }
A. Nothing is wrong C. main() cannot be public void func(String[] args) {
with the program declared public ref .arguments= args; } }
because question is
not public A. The program will fail C. The program will fail
B. Because main() is D. The main() to compile since the to compile since the
static, it may not argument list is static method main non static method
access non-static s incorrect. func cannot access
is trying to call the
without a reference the static member
non-static method variable ref
to an instance of
question func
29. You want to find out the value of the
last element of an array. You write the
following code. What will happen when B. The program will D. The program will fail
you compile and run it? compile and run to compile since
public class MyAr{ successfully method func is
public static void main(String argv[]){ trying to assign to
int[] i = new int[5]; the non static
System.out.println(i[5]); member variable
} arguments through
} the static member
variable ref
A. Compilation and C. Compilation and output
output of 0 of null 32. What will be the result of attempting to compile
B. Compilation and D. Compile time error the following program ?
runtime Exception public class Myclass {
long var;
public void Myclass(long param) { var=param;
30. Given the following code, which statement can
}
be placed at the indicated position without
public static void main(String ar[]) {
causing compile time error
Myclassa,b;
public class Thisusage{
a=new Myclass();
int planets;
b=new Myclass();
static int sums;
} }
public void gaze() {
A. A compilation error C. A compilation error
inti;
will be encountered, will be encountered
// ……….insert statements here….
since constructors since the class does
}
should not specify not have a default
}
the return value constructor
Select valid answers
B. The program will D. A compilation error
compile correctly will be encountered
A. i=this.planets; C. i=this.sums;
since the class does
not have a
B. this=new D. this.i=4;
constructor
Thisusage();
accepting a single
argument of type int
34. class X
33. class One {
{ int i;
int i; }
void display() class Y extends X
{ {
System.out.println(i); int j;
} void display()
} {
class Two extends One super.i = j + 1;
{ System.out.println(j + " " + i);
int j; }
void display() }
{ class inherit
System.out.println(j); {
} public static void main(String xz[])
} {
class inherit Y obj = new Y();
{ obj.i=1;
public static void main(String abc[]) obj.j=2;
{ obj.display();
Two obj = new Two(); }
obj.i=1; }
obj.j=2; Predict the output of the above code.
obj.display(); A. 2 2 C. 3 3
} B. 23 D. 3 2
} 35. class P
Judge and mark the correct output of the code. {
public int i;
A. 0 C. 1 public int j;
B. 2 D. Compilation Error P()
Explanation: Class One & class Two both contain {
display() method, class Two inherits class One, when i = 1;
display() method is called by object of class Two, j = 2;
display() method of class Two is executed rather than }
that of Class One. }
class Q extends P
{
int a;
Q()
{
super();
}
}
class super_use
{
public static void main(String ar[])
{
Q obj = new Q();
System.out.println(obj.i + " " + obj.j)
}
}
A. 12 C. 2 1 38 Analyze the code and choose the correct
B. Runtime Error D. Compilation Error . output?
Explanation: Keyword super is used to call class Point {
constructor of class P by constructor of class Q. int m_x, m_y;
Constructor of P initializes i & j to 1 & 2 public Point(int x, int y) { m_x =
respectively. x; m_y = y; }
public static void main(String args[])
36. Analyze the code and choose the correct {
output? Point p = new Point();
class ZZ }
{ }
int b = 50;
} A. No output C. O
B. Runtime Error D. Compile time Error
class QQ extends ZZ Explanation: A constructor with 2 int type
{ argument is defined in class. So, default
int b = 20; argument is not called and a compile time error
} will come.

public class MainClass 39 Using which of the following, multiple


{ . inheritances in Java can be implemented?
public static void main(String[] ar)
{ A. interfaces C. threads
ZZ a = new ZZ(); B. protected methods D. AWT

System.out.println(a.b); 40. One class extends two classes and both have
} method with same name and signature.
} Analyze the above statement and predict the
outcome??
A. 20 C. 50 A. Runtime Error C. Compile time Error
B. Runtime Error D. Compilation Error B. Code runs D. First called method
Explanation: Object a is of type ZZ, so the value successfully is executed
of variable b will be of Class ZZ’ s value of b. successfully
Explanation: In case of such conflict, compiler
will not be able to link a method call due to
37. Predict the output? ambiguity. It will throw compile time error.
package main; 41. __________keyword must be used to inherit a
class T { class.
int t = 20; A. Super C. This
} B. Extent D. extends
class Main {
public static void main(String a[]) { 42. Which of these keywords is used to refer to
T t1 = new T(); member of base class from a sub class?
System.out.println(t1.t); A. Upper C. super
} B. This D. none
} 43. Which method is called by Garbage collection
A. 20 C. 0 thread just before collecting eligible Objects ?
B. Runtime Error D. Compile time Error A. Final C. finalize
B. finally D. gc
47. class sessionalTestII {
public static void main (String[] args) {
44 When class is declared as abstract , then ____ Error error = new Error();
A. It can not inherit any C. Its subclass can not Exception exception = new Exception();
class be created System.out.print((exception instanceof
B. It can not have D. Its object can not be Throwable) + ",");
methods created System.out.print(error instanceof
Throwable);
}}
45. Predict the output of the following program. false,false C. true,true
abstract class Question false,true D. true,false
{ 48. What will happen if we provide concrete
public int a; implementation of method in interface?
demo() A. The concrete class C. Runtime exception
{ implementing that is thrown
a = 10; method need not
} provide
abstract public void set(); implementation of
abstract final public void get(); that method
} B. Compilation failure D. Method not found
class QuestionBank extends Question exception is thrown
{
public void set(int a) 49. What will happen when constructor is defined
{ for an interface?
this.a = a; A. Compilation failure C. The interface
} compiles
final public void get() successfully
{ B. Runtime Exception D. The implementing
System.out.println("a = " + a); class will throw
} exception
public static void main(String[] args) 50. What will be the result after compiling the
{ code given below.
QuestionBank obj = new QuestionBank(); public class Test implements Runnable{
obj.set(20); public static void main(String[] args){
obj.get(); Thread t = new Thread(this);
} t.start();
} }
A. A=10 C. B=20 public void run(){
B. Compilation Error D. Run-time Error System.out.println("test");
Explanation: Final method can’t be overridden. Thus, }
an abstract function can’t be final. }
46. State whether the following statements about
the advantages of organizing classes into A. The program does C. The program
packages are True or False. not compile because compiles fine, but it
i) Two classes in two different packages can this cannot be does not print
not have the same name. referenced in a static anything because t
ii) The classes contained in the packages of method. does not invoke the
other programs can be easily reused. run() method
A. True, False C. False, True
B. True, True D. False, False
B. The program D. None of the above }}
compiles fine, but it A. One C. One Two
does not print B. Two D. Compilation Error
anything because t 54. What will be the result of executing the
does not invoke the following code?
run() method public class Test{
public void divide(int a, int b){
51. Which of the following constructor of class try{
Thread is valid one? int c = b / a;
A. Thread(Runnable C. Thread(Runnable }catch(Exception e){
threadOb, int threadOb, String System.out.print("Exception ");
priority) threadName) }finally{
B. Thread(int priority) D. Thread(String System.out.println("Finally");
threadName, int }
priority)
public static void main(String args[]){
52. Determine output of the following program Test t = new Test();
code? t.divide(0,3);
public class Test{ }}
public static void main(String args[]){ Exception C. Finally
int i; Exception Finally D. Compilation Error
try{
i = calculate();
55. Predict the output of the following program.
System.out.println(i);
class Test { String str = "a";
}catch(Exception e){
void A() { try {
System.out.println("Error occured");
str +="b";
}
B(); }
}
catch (Exception e) {
str += "c";
static int calculate(){
} }
return (7/2);
void B() throws Exception
}
{ try { str += "d";
}
C(); }
catch(Exception e){
A. Compilation Error C. Error occurred
throw new Exception(); }
B. 3.5 D. 3
finally { str += "e“; }
str += "f“; }
53. What will be the output?
void C() throws Exception {
class MyClass{
throw new Exception(); }
public String test(){
try{
void display() {
System.out.print("One");
System.out.println(str);
return "";
}
}
public static void main(String[] args)
finally{
{
System.out.print("Two");
Test object = new Test();
}
object.A();
}
object.display();
}
}}
public class Test{
public static void main(String args[]){
abdef C. abdec
MyClass m = new MyClass();
abdefc D. abd
m.test();

You might also like