SlideShare a Scribd company logo
1 of 11
Download to read offline
JAVA QUESTIONS 3
1.Which is a reserved word in the Java programming language?
A. method
B. native
C. subclasses
D. reference
E. array
Answer: Option B
2.Which is a valid keyword in java?
A. interface
B. string
C. Float
D. unsigned
Answer: Option A
3.Which three are legal array declarations?
1. int [] myScores [];
2. char [] myChars;
3. int [6] myScores;
4. Dog myDogs [];
5. Dog myDogs [7];
A. 1, 2, 4
B. 2, 4, 5
C. 2, 3, 4
D. All are correct.
Answer: Option A
4.What will be the output of the program?
class Test
{
public static void main(String [] args)
{
Test p = new Test();
p.start();
}
void start()
{
boolean b1 = false;
boolean b2 = fix(b1);
System.out.println(b1 + " " + b2);
}
boolean fix(boolean b1)
{
b1 = true;
return b1;
}
}
A. true true
B. false true
C. true false
D. false false
Answer: Option B
5.What will be the output of the program?
public class Foo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
A. Finally
B. Compilation fails.
C. The code runs with no output.
D. An exception is thrown at runtime.
Answer: Option A
6.
class Boo
{
Boo(String s) { }
Boo() { }
}
class Bar extends Boo
{
Bar() { }
Bar(String s) {super(s);}
void zoo()
{
// insert code here
}
}
which one create an anonymous inner class from within class Bar?
A. Boo f = new Boo(24) { };
B. Boo f = new Bar() { };
C. Bar f = new Boo(String s) { };
D. Boo f = new Boo.Bar(String s) { };
Answer: Option B
7.
class HappyGarbage01
{
public static void main(String args[])
{
HappyGarbage01 h = new HappyGarbage01();
h.methodA(); /* Line 6 */
}
Object methodA()
{
Object obj1 = new Object();
Object [] obj2 = new Object[1];
obj2[0] = obj1;
obj1 = null;
return obj2[0];
}
}
Where will be the most chance of the garbage collector being invoked?
A. After line 9
B. After line 10
C. After line 11
D. Garbage collector never invoked in methodA()
Answer: Option D
8.Which of the following are valid calls to Math.max?
1. Math.max(1,4)
2. Math.max(2.3, 5)
3. Math.max(1, 3, 5, 7)
4. Math.max(-1.5, -2.8f)
A. 1, 2 and 4
B. 2, 3 and 4
C. 1, 2 and 3
D. 3 and 4
Answer: Option A
9.
public class Myfile
{
public static void main (String[] args)
{
String biz = args[1];
String baz = args[2];
String rip = args[3];
System.out.println("Arg is " + rip);
}
}
Select how you would start the program to cause it to print: Arg is 2
A. java Myfile 222
B. java Myfile 1 2 2 3 4
C. java Myfile 1 3 2 2
D. java Myfile 0 1 2 3
Answer: Option C
10.What will be the output of the program?
String x = new String("xyz");
String y = "abc";
x = x + y;
How many String objects have been created?
A. 2
B. 3
C. 4
D. 5
Answer: Option C
11.You want subclasses in any package to have access to members of a superclass. Which is the
most restrictive access that accomplishes this objective?
A. public
B. private
C. protected
D. transient
Answer: Option C
12.
public class Outer
{
public void someOuterMethod()
{
//Line 5
}
public class Inner { }
public static void main(String[] argv)
{
Outer ot = new Outer();
//Line 10
}
}
Which of the following code fragments inserted, will allow to compile?
A. new Inner(); //At line 5
B. new Inner(); //At line 10
C. new ot.Inner(); //At line 10
D. new Outer.Inner(); //At line 10
Answer: Option A
13.What is the most restrictive access modifier that will allow members of one class to have access
to members of another class in the same package?
A. public
B. abstract
C. protected
D. synchronized
E. default access
Answer: Option E
14.Which of the following is/are legal method declarations?
1. protected abstract void m1();
2. static final void m1(){}
3. synchronized public final void m1() {}
4. private native void m1();
A. 1 and 3
B. 2 and 4
C. 1 only
D. All of them are legal declarations.
Answer: Option D
15.Which cause a compiler error?
A. int[ ] scores = {3, 5, 7};
B. int [ ][ ] scores = {2,7,6}, {9,3,45};
C. String cats[ ] = {"Fluffy", "Spot", "Zeus"};
D. boolean results[ ] = new boolean [] {true, false, true};
E. Integer results[ ] = {new Integer(3), new Integer(5), new Integer(8)};
Answer: Option B
16.Which three are valid method signatures in an interface?
1. private int getArea();
2. public float getVol(float x);
3. public void main(String [] args);
4. public static void main(String [] args);
5. boolean setFlag(Boolean [] test);
A. 1 and 2
B. 2, 3 and 5
C. 3, 4, and 5
D. 2 and 4
Answer: Option B
17.You want a class to have access to members of another class in the same package. Which is the
most restrictive access that accomplishes this objective?
A. public
B. private
C. protected
D. default access
Answer: Option D
18.
public void foo( boolean a, boolean b)
{
if( a )
{
System.out.println("A"); /* Line 5 */
}
else if(a && b) /* Line 7 */
{
System.out.println( "A && B");
}
else /* Line 11 */
{
if ( !b )
{
System.out.println( "notB") ;
}
else
{
System.out.println( "ELSE" ) ;
}
}
}
A. If a is true and b is true then the output is "A && B"
B. If a is true and b is false then the output is "notB"
C. If a is false and b is true then the output is "ELSE"
D. If a is false and b is false then the output is "ELSE"
Answer: Option C
19.
switch(x)
{
default:
System.out.println("Hello");
}
Which two are acceptable types for x?
1. byte
2. long
3. char
4. float
5. Short
6. Long
A. 1 and 3
B. 2 and 4
C. 3 and 5
D. 4 and 6
Answer: Option A
20.Which collection class allows you to grow or shrink its size and provides indexed access to its
elements, but whose methods are not synchronized?
A. java.util.HashSet
B. java.util.LinkedHashSet
C. java.util.List
D. java.util.ArrayList
Answer: Option D
21.Which three are methods of the Object class?
1. notify();
2. notifyAll();
3. isInterrupted();
4. synchronized();
5. interrupt();
6. wait(long msecs);
7. sleep(long msecs);
8. yield();
A. 1, 2, 4
B. 2, 4, 5
C. 1, 2, 6
D. 2, 3, 4
Answer: Option C
22.
class X implements Runnable
{
public static void main(String args[])
{
/* Missing code? */
}
public void run() {}
}
Which of the following line of code is suitable to start a thread ?
A. Thread t = new Thread(X);
B. Thread t = new Thread(X); t.start();
C. X run = new X(); Thread t = new Thread(run); t.start();
D. Thread t = new Thread(); x.run();
Answer: Option C
23.What will be the output of the program (when you run with the -ea option) ?
public class Test
{
public static void main(String[] args)
{
int x = 0;
assert (x > 0) : "assertion failed"; /* Line 6 */
System.out.println("finished");
}
}
A. finished
B. Compilation fails.
C. An AssertionError is thrown.
D. An AssertionError is thrown and finished is output.
Answer: Option C
24.
public class Test
{
public void foo()
{
assert false; /* Line 5 */
assert false; /* Line 6 */
}
public void bar()
{
while(true)
{
assert false; /* Line 12 */
}
assert false; /* Line 14 */
}
}
What causes compilation to fail?
A. Line 5
B. Line 6
C. Line 12
D. Line 14
Answer: Option D
25.
System.out.print("Start ");
try
{
System.out.print("Hello world");
throw new FileNotFoundException();
}
System.out.print(" Catch Here "); /* Line 7 */
catch(EOFException e)
{
System.out.print("End of file exception");
}
catch(FileNotFoundException e)
{
System.out.print("File not found");
}
and given that EOFException and FileNotFoundException are both subclasses
of IOException, and further assuming this block of code is placed into a class, which statement is
most true concerning this code?
A. The code will not compile.
B. Code output: Start Hello world File Not Found.
C. Code output: Start Hello world End of file exception.
D. Code output: Start Hello world Catch Here File not found.
Answer: Option A

More Related Content

What's hot

2 object orientation-copy
2 object orientation-copy2 object orientation-copy
2 object orientation-copy
Joel Campos
 

What's hot (18)

Cbse marking scheme 2006 2011
Cbse marking scheme 2006  2011Cbse marking scheme 2006  2011
Cbse marking scheme 2006 2011
 
Core java
Core javaCore java
Core java
 
Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answers
 
Computer science sqp
Computer science sqpComputer science sqp
Computer science sqp
 
Part - 3 Cpp programming Solved MCQ
Part - 3 Cpp programming Solved MCQ  Part - 3 Cpp programming Solved MCQ
Part - 3 Cpp programming Solved MCQ
 
Java Questions and Answers
Java Questions and AnswersJava Questions and Answers
Java Questions and Answers
 
Java Puzzlers
Java PuzzlersJava Puzzlers
Java Puzzlers
 
Puzles C#
Puzles C#Puzles C#
Puzles C#
 
Sample Paper 2 Class XI (Computer Science)
Sample Paper 2 Class XI (Computer Science)Sample Paper 2 Class XI (Computer Science)
Sample Paper 2 Class XI (Computer Science)
 
E5
E5E5
E5
 
2 object orientation-copy
2 object orientation-copy2 object orientation-copy
2 object orientation-copy
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
 
conditional statements
conditional statementsconditional statements
conditional statements
 
Complicated declarations in c
Complicated declarations in cComplicated declarations in c
Complicated declarations in c
 
C MCQ
C MCQC MCQ
C MCQ
 
Soln dc05
Soln dc05Soln dc05
Soln dc05
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Unit 3
Unit 3 Unit 3
Unit 3
 

Similar to Java Interview Questions -3

Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
fntsofttech
 
Examf cs-cs141-2-17
Examf cs-cs141-2-17Examf cs-cs141-2-17
Examf cs-cs141-2-17
Fahadaio
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
MaruMengesha
 

Similar to Java Interview Questions -3 (20)

Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
Scjp6.0
Scjp6.0Scjp6.0
Scjp6.0
 
Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentals
 
Conceitos Fundamentais de Orientação a Objetos
Conceitos Fundamentais de Orientação a ObjetosConceitos Fundamentais de Orientação a Objetos
Conceitos Fundamentais de Orientação a Objetos
 
Questões de Certificação SCJP
Questões de Certificação SCJPQuestões de Certificação SCJP
Questões de Certificação SCJP
 
T1
T1T1
T1
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
 
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
 
Technical questions
Technical questionsTechnical questions
Technical questions
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
 
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02) Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
 
1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional
 
FSOFT - Test Java Exam
FSOFT - Test Java ExamFSOFT - Test Java Exam
FSOFT - Test Java Exam
 
Part - 2 Cpp programming Solved MCQ
Part - 2  Cpp programming Solved MCQ Part - 2  Cpp programming Solved MCQ
Part - 2 Cpp programming Solved MCQ
 
Multiple Choice Questions for Java interfaces and exception handling
Multiple Choice Questions for Java interfaces and exception handlingMultiple Choice Questions for Java interfaces and exception handling
Multiple Choice Questions for Java interfaces and exception handling
 
Examf cs-cs141-2-17
Examf cs-cs141-2-17Examf cs-cs141-2-17
Examf cs-cs141-2-17
 
Multiple choice questions for Java io,files and inheritance
Multiple choice questions for Java io,files and inheritanceMultiple choice questions for Java io,files and inheritance
Multiple choice questions for Java io,files and inheritance
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
 
Computer programming mcqs
Computer programming mcqsComputer programming mcqs
Computer programming mcqs
 
C test
C testC test
C test
 

More from zynofustechnology

More from zynofustechnology (16)

JAVA QUESTIONS -6
JAVA QUESTIONS -6JAVA QUESTIONS -6
JAVA QUESTIONS -6
 
JAVA QUESTIONS FOR INTERVIEW-3
JAVA QUESTIONS FOR INTERVIEW-3JAVA QUESTIONS FOR INTERVIEW-3
JAVA QUESTIONS FOR INTERVIEW-3
 
PYTHON INTERVIEW QUESTIONS-4
PYTHON INTERVIEW QUESTIONS-4PYTHON INTERVIEW QUESTIONS-4
PYTHON INTERVIEW QUESTIONS-4
 
PYTHON INTERVIEW QUESTIONS-2
PYTHON INTERVIEW QUESTIONS-2PYTHON INTERVIEW QUESTIONS-2
PYTHON INTERVIEW QUESTIONS-2
 
JAVA INTERVIEW QUESTIONS -3
JAVA INTERVIEW QUESTIONS -3JAVA INTERVIEW QUESTIONS -3
JAVA INTERVIEW QUESTIONS -3
 
Java Interview Questions-5
Java Interview Questions-5Java Interview Questions-5
Java Interview Questions-5
 
Java Interview Questions - 1
Java Interview Questions - 1Java Interview Questions - 1
Java Interview Questions - 1
 
SQL Interview Questions For Experienced
SQL Interview Questions For ExperiencedSQL Interview Questions For Experienced
SQL Interview Questions For Experienced
 
Software Testing Interview Questions For Experienced
Software Testing Interview Questions For ExperiencedSoftware Testing Interview Questions For Experienced
Software Testing Interview Questions For Experienced
 
Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experienced
 
Python Interview Questions For Freshers
Python Interview Questions For FreshersPython Interview Questions For Freshers
Python Interview Questions For Freshers
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
 
HR interview questions
HR interview questionsHR interview questions
HR interview questions
 
Digital marketing questions -3
Digital marketing questions -3Digital marketing questions -3
Digital marketing questions -3
 
Digital marketing questions -2
Digital marketing questions -2Digital marketing questions -2
Digital marketing questions -2
 
Digital marketing questions 1
Digital marketing questions  1Digital marketing questions  1
Digital marketing questions 1
 

Recently uploaded

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Recently uploaded (20)

WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 

Java Interview Questions -3

  • 1. JAVA QUESTIONS 3 1.Which is a reserved word in the Java programming language? A. method B. native C. subclasses D. reference E. array Answer: Option B 2.Which is a valid keyword in java? A. interface B. string C. Float D. unsigned Answer: Option A 3.Which three are legal array declarations? 1. int [] myScores []; 2. char [] myChars; 3. int [6] myScores; 4. Dog myDogs []; 5. Dog myDogs [7]; A. 1, 2, 4 B. 2, 4, 5 C. 2, 3, 4 D. All are correct. Answer: Option A 4.What will be the output of the program? class Test {
  • 2. public static void main(String [] args) { Test p = new Test(); p.start(); } void start() { boolean b1 = false; boolean b2 = fix(b1); System.out.println(b1 + " " + b2); } boolean fix(boolean b1) { b1 = true; return b1; } } A. true true B. false true C. true false D. false false Answer: Option B 5.What will be the output of the program? public class Foo { public static void main(String[] args) { try { return; } finally { System.out.println( "Finally" ); } } } A. Finally B. Compilation fails. C. The code runs with no output. D. An exception is thrown at runtime. Answer: Option A 6.
  • 3. class Boo { Boo(String s) { } Boo() { } } class Bar extends Boo { Bar() { } Bar(String s) {super(s);} void zoo() { // insert code here } } which one create an anonymous inner class from within class Bar? A. Boo f = new Boo(24) { }; B. Boo f = new Bar() { }; C. Bar f = new Boo(String s) { }; D. Boo f = new Boo.Bar(String s) { }; Answer: Option B 7. class HappyGarbage01 { public static void main(String args[]) { HappyGarbage01 h = new HappyGarbage01(); h.methodA(); /* Line 6 */ } Object methodA() { Object obj1 = new Object(); Object [] obj2 = new Object[1]; obj2[0] = obj1; obj1 = null; return obj2[0]; } } Where will be the most chance of the garbage collector being invoked? A. After line 9 B. After line 10 C. After line 11 D. Garbage collector never invoked in methodA() Answer: Option D
  • 4. 8.Which of the following are valid calls to Math.max? 1. Math.max(1,4) 2. Math.max(2.3, 5) 3. Math.max(1, 3, 5, 7) 4. Math.max(-1.5, -2.8f) A. 1, 2 and 4 B. 2, 3 and 4 C. 1, 2 and 3 D. 3 and 4 Answer: Option A 9. public class Myfile { public static void main (String[] args) { String biz = args[1]; String baz = args[2]; String rip = args[3]; System.out.println("Arg is " + rip); } } Select how you would start the program to cause it to print: Arg is 2 A. java Myfile 222 B. java Myfile 1 2 2 3 4 C. java Myfile 1 3 2 2 D. java Myfile 0 1 2 3 Answer: Option C 10.What will be the output of the program? String x = new String("xyz"); String y = "abc"; x = x + y; How many String objects have been created? A. 2 B. 3
  • 5. C. 4 D. 5 Answer: Option C 11.You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective? A. public B. private C. protected D. transient Answer: Option C 12. public class Outer { public void someOuterMethod() { //Line 5 } public class Inner { } public static void main(String[] argv) { Outer ot = new Outer(); //Line 10 } } Which of the following code fragments inserted, will allow to compile? A. new Inner(); //At line 5 B. new Inner(); //At line 10 C. new ot.Inner(); //At line 10 D. new Outer.Inner(); //At line 10 Answer: Option A 13.What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package? A. public B. abstract C. protected
  • 6. D. synchronized E. default access Answer: Option E 14.Which of the following is/are legal method declarations? 1. protected abstract void m1(); 2. static final void m1(){} 3. synchronized public final void m1() {} 4. private native void m1(); A. 1 and 3 B. 2 and 4 C. 1 only D. All of them are legal declarations. Answer: Option D 15.Which cause a compiler error? A. int[ ] scores = {3, 5, 7}; B. int [ ][ ] scores = {2,7,6}, {9,3,45}; C. String cats[ ] = {"Fluffy", "Spot", "Zeus"}; D. boolean results[ ] = new boolean [] {true, false, true}; E. Integer results[ ] = {new Integer(3), new Integer(5), new Integer(8)}; Answer: Option B 16.Which three are valid method signatures in an interface? 1. private int getArea(); 2. public float getVol(float x); 3. public void main(String [] args); 4. public static void main(String [] args); 5. boolean setFlag(Boolean [] test); A. 1 and 2 B. 2, 3 and 5 C. 3, 4, and 5 D. 2 and 4
  • 7. Answer: Option B 17.You want a class to have access to members of another class in the same package. Which is the most restrictive access that accomplishes this objective? A. public B. private C. protected D. default access Answer: Option D 18. public void foo( boolean a, boolean b) { if( a ) { System.out.println("A"); /* Line 5 */ } else if(a && b) /* Line 7 */ { System.out.println( "A && B"); } else /* Line 11 */ { if ( !b ) { System.out.println( "notB") ; } else { System.out.println( "ELSE" ) ; } } } A. If a is true and b is true then the output is "A && B" B. If a is true and b is false then the output is "notB" C. If a is false and b is true then the output is "ELSE" D. If a is false and b is false then the output is "ELSE" Answer: Option C 19.
  • 8. switch(x) { default: System.out.println("Hello"); } Which two are acceptable types for x? 1. byte 2. long 3. char 4. float 5. Short 6. Long A. 1 and 3 B. 2 and 4 C. 3 and 5 D. 4 and 6 Answer: Option A 20.Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized? A. java.util.HashSet B. java.util.LinkedHashSet C. java.util.List D. java.util.ArrayList Answer: Option D 21.Which three are methods of the Object class? 1. notify(); 2. notifyAll(); 3. isInterrupted(); 4. synchronized(); 5. interrupt(); 6. wait(long msecs); 7. sleep(long msecs);
  • 9. 8. yield(); A. 1, 2, 4 B. 2, 4, 5 C. 1, 2, 6 D. 2, 3, 4 Answer: Option C 22. class X implements Runnable { public static void main(String args[]) { /* Missing code? */ } public void run() {} } Which of the following line of code is suitable to start a thread ? A. Thread t = new Thread(X); B. Thread t = new Thread(X); t.start(); C. X run = new X(); Thread t = new Thread(run); t.start(); D. Thread t = new Thread(); x.run(); Answer: Option C 23.What will be the output of the program (when you run with the -ea option) ? public class Test { public static void main(String[] args) { int x = 0; assert (x > 0) : "assertion failed"; /* Line 6 */ System.out.println("finished"); } }
  • 10. A. finished B. Compilation fails. C. An AssertionError is thrown. D. An AssertionError is thrown and finished is output. Answer: Option C 24. public class Test { public void foo() { assert false; /* Line 5 */ assert false; /* Line 6 */ } public void bar() { while(true) { assert false; /* Line 12 */ } assert false; /* Line 14 */ } } What causes compilation to fail? A. Line 5 B. Line 6 C. Line 12 D. Line 14 Answer: Option D 25. System.out.print("Start "); try { System.out.print("Hello world");
  • 11. throw new FileNotFoundException(); } System.out.print(" Catch Here "); /* Line 7 */ catch(EOFException e) { System.out.print("End of file exception"); } catch(FileNotFoundException e) { System.out.print("File not found"); } and given that EOFException and FileNotFoundException are both subclasses of IOException, and further assuming this block of code is placed into a class, which statement is most true concerning this code? A. The code will not compile. B. Code output: Start Hello world File Not Found. C. Code output: Start Hello world End of file exception. D. Code output: Start Hello world Catch Here File not found. Answer: Option A