SlideShare a Scribd company logo
1 of 10
•   Which of the following is correct syntax for an Abstract class ?

(a) abstract double area() { }

(b) abstract double area()

(c) abstract double area();

(d) abstract double area(); { }

ANS: (c)

•   A class can be converted to a thread by implementing the interface __________

(a) Thread

(b) Runnable

ANS: (b)

•   What is the output of following block of program ?

boolean var = false;

if(var = true) {

System.out.println("TRUE");

} else {

System.out.println("FALSE");

}



(a) TRUE

(b) FALSE

(c) Compilation Error

(d) Run-time Error

ANS: (a)

EXPLANATION: The code compiles and runs fine and the 'if' test succeeds because 'var' is set to
'true' (rather than tested for 'true') in the 'if' argument.

•   A Vector is declared as follows. What happens if the code tried to add 6 th element to
    this Vector new vector(5,10)

(a) The element will be successfully added

(b) ArrayIndexOutOfBounds Exception
(c) The Vector allocates space to accommodate up to 15 elements

ANS: (a) and (c)

EXPLANATION: The 1 st argument in the constructor is the initial size of Vector and the 2 nd
argument in the constructor is the growth in size (for each allocation)

This Vector is created with 5 elements and when an extra element (6 th one) is tried to be
added, the vector grows in size by 10.

•     What is the output of following piece of code ?

int x = 2;

switch (x) {

    case 1:System.out.println("1");

    case 2:

    case 3:System.out.println("3");

    case 4:

    case 5:System.out.println("5");

}

(a) No output

(b) 3 and 5

(c) 1, 3 and 5

(d) 3

ANS: (b)

•     Which of the following 2 methods executes faster ?

class Trial {

         String _member;

         void method1() {

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

                        _member += "test";

                 }

         }

         void method2() {
String temp;

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

                        temp += "test";

                }

                _member = temp;

         }

}



(a) method1()

(b) method2()

(c) Both method1() and method2() takes same time for execution

ANS: (b)

Accessing method variables requires less overhead than accessing class variables.

•   Integer.parseInt("12a") returns

(a) Exception

(b) 1

(c) 0

(d) -1

ANS: (a)

•   By default, Strings to functions are passed using the method

(a) Call by Value

(b) Call by Reference

(c) Strings cannot be passed to function

ANS: (b)

String is a class defined in java.lang and in java all classes are passed by reference.
•   What is the output of following program ?

class Test {

          public static void main(String args[]) {

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

                         System.out.println(i--);

                 }

          }

}



(a) Goes into infinite loop

(b) 0,1

(c) 0,1,2

(d) None



ANS: (a)

•   It is the reference to a class that extends THREAD. Then how to suspend the execution
    of this thread?

(a) t.yield()

(b) yield(t)

(c) yield()

(d) yield(100) where 100 is the milli seconds of time

•   How many String objects are created by the following statements ?

String str = " a+b=10 ";

trim(str)

str.replace(+,-);

(a) 1

(b) 2

(c) 3

(d) 4
ANS: (c)

•       Cleaning operation in Java is done in the method

(a) finally()

(b) finalize()

(c) final()

•       If we want to read a very big text file with so many mega bytes of data, what shall we
        use ?

(a) FileInputStream

(b) InputStreamReader

•       What code, if written, below the (//code here) will display 0.



class Test {

           public static void main(String argv[]) {

                  int i=0;



                  //code here

           }

}

(a) System.out.println(i++)

(b) System.out.println(i+'0')

(c) System.out.println(i--)

(d) System.out.println(i)

ANS: (a),(c),(d)

The option (b) displays the ASCII value of '0'. So, the output in this case is: 48

    •    Which one of the following about Applet is true? (Choose all that applies)

           a. Applets are executed by console based-java run-time interpreter.

           b. Applets are executed by a Web Browser

           c. Applets are executed by an Applet Viewer
d. None of the Above



•   In applets which method is used to allocate memory to the components?

     a) start()

     b) stop()

     c) init()

     d) destroy()



•   While executing applets in browser the tag specified in the HTML browser is

     a) <html></html>

     b) <appletviewer></appletviewer>

     c) <applet></applet>

     d) <xml></xml>

•   Which of the following method is used to retrieve the base URL of the applet

     a) getAppletInfo()

     b) getDocumentInfo()

     c) getDocumentBase()

     d) getCodeBase()

•   The method used in applet to display image in the status bar is

     a) showInfo()

     b) showStatus()

     c) dialogStatus()

     d) dialogInfo()

•   The method used to dynamically specify the size to the applet is
a) pack()

     b) size()

     c) resize()

     d) height, width

•   Expand AWT

     a) Applet Windows Tool Kit.

     b) Applications Windows Tool Kit

     c) Abstract Windows Tool Kit

     d) None of the Above

•   Which one of the following is an Abstract Class?

     a. Graphics

     b. Color

     c. Menu

     d. Font

     e. None of the above

•   Which of the following is the default Layout Manager in Java?

     a. Border Layout Manager

     b. Flow Layout Manager

     c. Grid Bag Layout Manager

     d. Card Layout

     e. None of the Above.

•   In which Layout Manager extra space is placed in the Center region ?

     a) Border Layout Manager
b) Flow Layout Manager

         c) Grid Bag Layout Manager

         d) Card Layout

         e) None of the Above.

•       In which Layout Manager the container is divided into equally-sized
        rectangles, and one components is placed in the rectangles

                 a. Border Layout Manager

                 b. Flow Layout Manager

                 c. Grid Bag Layout Manager

                 d. Card Layout

                 e. Grid Layout

                 f. None of the Above.




         •    Which of the following are the features of swing components?

              a. Lightweight

              b. Portable

              c. Look & Feel

              d. All the above

    •    MVC stands for

             a. Model View Controller

             b. Model View Container

             c. Meta View Container
d. Model Volatile Container

•       Swing components are categorized into

            a. Applets and Applications

            b. Frames and Panels

            c. Containers and Controls

            d. none of above

    •    Window Event can be activated on the containers like

            a) JFrame

            b) JPanel

            c) Component

            d) Controls

    •    The method used to alter the displayed set of characters in the
         components like password field is

            a. setText()

            b. setLabel()

            c. echoChar()

            d. setEchoChar()

    •    The method used to add element in the combobox is

            a. addItem()

            b. addElement()

            c. addValue()

            d. setElement()

    •    Which methods is used to separate different menu items in the menu bar
a. addSeperator()

b. add(“-“)

c. addLine()

d. displaySeperator()

More Related Content

What's hot

Data structure - mcqs
Data structure - mcqsData structure - mcqs
Data structure - mcqssuthi
 
Csphtp1 16
Csphtp1 16Csphtp1 16
Csphtp1 16HUST
 
Categories for the Working C++ Programmer
Categories for the Working C++ ProgrammerCategories for the Working C++ Programmer
Categories for the Working C++ ProgrammerPlatonov Sergey
 
Address/Thread/Memory Sanitizer
Address/Thread/Memory SanitizerAddress/Thread/Memory Sanitizer
Address/Thread/Memory SanitizerPlatonov Sergey
 
Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentalsKapish Joshi
 
Technical aptitude test 2 CSE
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSESujata Regoti
 
Mining Source Code Improvement Patterns from Similar Code Review Works
Mining Source Code Improvement Patterns from Similar Code Review WorksMining Source Code Improvement Patterns from Similar Code Review Works
Mining Source Code Improvement Patterns from Similar Code Review WorksYuki Ueda
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guidekrtioplal
 
Technical aptitude Test 1 CSE
Technical aptitude Test 1 CSETechnical aptitude Test 1 CSE
Technical aptitude Test 1 CSESujata Regoti
 
Python programming workshop session 2
Python programming workshop session 2Python programming workshop session 2
Python programming workshop session 2Abdul Haseeb
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Saket Pathak
 
CDAC CCAT examination important question
CDAC CCAT examination important questionCDAC CCAT examination important question
CDAC CCAT examination important questionprabhatjon
 
Data structures and algorithms unit i
Data structures and algorithms unit iData structures and algorithms unit i
Data structures and algorithms unit isonalisraisoni
 
Java programming lab assignments
Java programming lab assignments Java programming lab assignments
Java programming lab assignments rajni kaushal
 

What's hot (20)

Data structure - mcqs
Data structure - mcqsData structure - mcqs
Data structure - mcqs
 
Csphtp1 16
Csphtp1 16Csphtp1 16
Csphtp1 16
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
07. Arrays
07. Arrays07. Arrays
07. Arrays
 
Categories for the Working C++ Programmer
Categories for the Working C++ ProgrammerCategories for the Working C++ Programmer
Categories for the Working C++ Programmer
 
Address/Thread/Memory Sanitizer
Address/Thread/Memory SanitizerAddress/Thread/Memory Sanitizer
Address/Thread/Memory Sanitizer
 
Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentals
 
Core java
Core javaCore java
Core java
 
Technical aptitude test 2 CSE
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSE
 
Mining Source Code Improvement Patterns from Similar Code Review Works
Mining Source Code Improvement Patterns from Similar Code Review WorksMining Source Code Improvement Patterns from Similar Code Review Works
Mining Source Code Improvement Patterns from Similar Code Review Works
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
 
Oops Paper
Oops PaperOops Paper
Oops Paper
 
Technical aptitude Test 1 CSE
Technical aptitude Test 1 CSETechnical aptitude Test 1 CSE
Technical aptitude Test 1 CSE
 
Python programming workshop session 2
Python programming workshop session 2Python programming workshop session 2
Python programming workshop session 2
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
 
CDAC CCAT examination important question
CDAC CCAT examination important questionCDAC CCAT examination important question
CDAC CCAT examination important question
 
Data structures and algorithms unit i
Data structures and algorithms unit iData structures and algorithms unit i
Data structures and algorithms unit i
 
c++ lab manual
c++ lab manualc++ lab manual
c++ lab manual
 
Java programming lab assignments
Java programming lab assignments Java programming lab assignments
Java programming lab assignments
 

Similar to Java questions1

200 mcq c++(Ankit dubey)
200 mcq c++(Ankit dubey)200 mcq c++(Ankit dubey)
200 mcq c++(Ankit dubey)Ankit Dubey
 
C aptitude 1st jan 2012
C aptitude 1st jan 2012C aptitude 1st jan 2012
C aptitude 1st jan 2012Kishor Parkhe
 
Prueba de conociemientos Fullsctack NET v2.docx
Prueba de conociemientos  Fullsctack NET v2.docxPrueba de conociemientos  Fullsctack NET v2.docx
Prueba de conociemientos Fullsctack NET v2.docxjairatuesta
 
this pdf very much useful for embedded c programming students
this pdf very much useful for embedded c programming studentsthis pdf very much useful for embedded c programming students
this pdf very much useful for embedded c programming studentspavan81088
 
ExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docxExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docxgitagrimston
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docxrosemarybdodson23141
 
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 inheritanceAbishek Purushothaman
 
SBI IT (Systems) Assistant Manager Question Paper
SBI IT (Systems) Assistant Manager Question PaperSBI IT (Systems) Assistant Manager Question Paper
SBI IT (Systems) Assistant Manager Question PaperHarish Rawat
 
CAPE Computer Science Unit 1 Paper 1 - Practice Paper
CAPE Computer Science Unit 1 Paper 1 - Practice PaperCAPE Computer Science Unit 1 Paper 1 - Practice Paper
CAPE Computer Science Unit 1 Paper 1 - Practice PaperAlex Stewart
 
C programming & data structure
C programming & data structureC programming & data structure
C programming & data structurerajeev_123
 
New microsoft office word document (3)
New microsoft office word document (3)New microsoft office word document (3)
New microsoft office word document (3)Sagar Kuchekar
 
Redo midterm
Redo midtermRedo midterm
Redo midtermIIUM
 

Similar to Java questions1 (20)

200 mcq c++(Ankit dubey)
200 mcq c++(Ankit dubey)200 mcq c++(Ankit dubey)
200 mcq c++(Ankit dubey)
 
C aptitude 1st jan 2012
C aptitude 1st jan 2012C aptitude 1st jan 2012
C aptitude 1st jan 2012
 
Prueba de conociemientos Fullsctack NET v2.docx
Prueba de conociemientos  Fullsctack NET v2.docxPrueba de conociemientos  Fullsctack NET v2.docx
Prueba de conociemientos Fullsctack NET v2.docx
 
Java Programming.pdf
Java Programming.pdfJava Programming.pdf
Java Programming.pdf
 
Gate-Cs 1994
Gate-Cs 1994Gate-Cs 1994
Gate-Cs 1994
 
this pdf very much useful for embedded c programming students
this pdf very much useful for embedded c programming studentsthis pdf very much useful for embedded c programming students
this pdf very much useful for embedded c programming students
 
Technical questions
Technical questionsTechnical questions
Technical questions
 
AJP.pdf
AJP.pdfAJP.pdf
AJP.pdf
 
ExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docxExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docx
 
hi
hihi
hi
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
 
Part - 3 Cpp programming Solved MCQ
Part - 3 Cpp programming Solved MCQ  Part - 3 Cpp programming Solved MCQ
Part - 3 Cpp programming Solved MCQ
 
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
 
SBI IT (Systems) Assistant Manager Question Paper
SBI IT (Systems) Assistant Manager Question PaperSBI IT (Systems) Assistant Manager Question Paper
SBI IT (Systems) Assistant Manager Question Paper
 
C MCQ
C MCQC MCQ
C MCQ
 
CAPE Computer Science Unit 1 Paper 1 - Practice Paper
CAPE Computer Science Unit 1 Paper 1 - Practice PaperCAPE Computer Science Unit 1 Paper 1 - Practice Paper
CAPE Computer Science Unit 1 Paper 1 - Practice Paper
 
C programming & data structure
C programming & data structureC programming & data structure
C programming & data structure
 
Overview of the Hive Stinger Initiative
Overview of the Hive Stinger InitiativeOverview of the Hive Stinger Initiative
Overview of the Hive Stinger Initiative
 
New microsoft office word document (3)
New microsoft office word document (3)New microsoft office word document (3)
New microsoft office word document (3)
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
 

Java questions1

  • 1. Which of the following is correct syntax for an Abstract class ? (a) abstract double area() { } (b) abstract double area() (c) abstract double area(); (d) abstract double area(); { } ANS: (c) • A class can be converted to a thread by implementing the interface __________ (a) Thread (b) Runnable ANS: (b) • What is the output of following block of program ? boolean var = false; if(var = true) { System.out.println("TRUE"); } else { System.out.println("FALSE"); } (a) TRUE (b) FALSE (c) Compilation Error (d) Run-time Error ANS: (a) EXPLANATION: The code compiles and runs fine and the 'if' test succeeds because 'var' is set to 'true' (rather than tested for 'true') in the 'if' argument. • A Vector is declared as follows. What happens if the code tried to add 6 th element to this Vector new vector(5,10) (a) The element will be successfully added (b) ArrayIndexOutOfBounds Exception
  • 2. (c) The Vector allocates space to accommodate up to 15 elements ANS: (a) and (c) EXPLANATION: The 1 st argument in the constructor is the initial size of Vector and the 2 nd argument in the constructor is the growth in size (for each allocation) This Vector is created with 5 elements and when an extra element (6 th one) is tried to be added, the vector grows in size by 10. • What is the output of following piece of code ? int x = 2; switch (x) { case 1:System.out.println("1"); case 2: case 3:System.out.println("3"); case 4: case 5:System.out.println("5"); } (a) No output (b) 3 and 5 (c) 1, 3 and 5 (d) 3 ANS: (b) • Which of the following 2 methods executes faster ? class Trial { String _member; void method1() { for(int i=0;i<2048;i++) { _member += "test"; } } void method2() {
  • 3. String temp; for(int i=0;i<2048;i++) { temp += "test"; } _member = temp; } } (a) method1() (b) method2() (c) Both method1() and method2() takes same time for execution ANS: (b) Accessing method variables requires less overhead than accessing class variables. • Integer.parseInt("12a") returns (a) Exception (b) 1 (c) 0 (d) -1 ANS: (a) • By default, Strings to functions are passed using the method (a) Call by Value (b) Call by Reference (c) Strings cannot be passed to function ANS: (b) String is a class defined in java.lang and in java all classes are passed by reference.
  • 4. What is the output of following program ? class Test { public static void main(String args[]) { for(int i=0;i<2;i++) { System.out.println(i--); } } } (a) Goes into infinite loop (b) 0,1 (c) 0,1,2 (d) None ANS: (a) • It is the reference to a class that extends THREAD. Then how to suspend the execution of this thread? (a) t.yield() (b) yield(t) (c) yield() (d) yield(100) where 100 is the milli seconds of time • How many String objects are created by the following statements ? String str = " a+b=10 "; trim(str) str.replace(+,-); (a) 1 (b) 2 (c) 3 (d) 4
  • 5. ANS: (c) • Cleaning operation in Java is done in the method (a) finally() (b) finalize() (c) final() • If we want to read a very big text file with so many mega bytes of data, what shall we use ? (a) FileInputStream (b) InputStreamReader • What code, if written, below the (//code here) will display 0. class Test { public static void main(String argv[]) { int i=0; //code here } } (a) System.out.println(i++) (b) System.out.println(i+'0') (c) System.out.println(i--) (d) System.out.println(i) ANS: (a),(c),(d) The option (b) displays the ASCII value of '0'. So, the output in this case is: 48 • Which one of the following about Applet is true? (Choose all that applies) a. Applets are executed by console based-java run-time interpreter. b. Applets are executed by a Web Browser c. Applets are executed by an Applet Viewer
  • 6. d. None of the Above • In applets which method is used to allocate memory to the components? a) start() b) stop() c) init() d) destroy() • While executing applets in browser the tag specified in the HTML browser is a) <html></html> b) <appletviewer></appletviewer> c) <applet></applet> d) <xml></xml> • Which of the following method is used to retrieve the base URL of the applet a) getAppletInfo() b) getDocumentInfo() c) getDocumentBase() d) getCodeBase() • The method used in applet to display image in the status bar is a) showInfo() b) showStatus() c) dialogStatus() d) dialogInfo() • The method used to dynamically specify the size to the applet is
  • 7. a) pack() b) size() c) resize() d) height, width • Expand AWT a) Applet Windows Tool Kit. b) Applications Windows Tool Kit c) Abstract Windows Tool Kit d) None of the Above • Which one of the following is an Abstract Class? a. Graphics b. Color c. Menu d. Font e. None of the above • Which of the following is the default Layout Manager in Java? a. Border Layout Manager b. Flow Layout Manager c. Grid Bag Layout Manager d. Card Layout e. None of the Above. • In which Layout Manager extra space is placed in the Center region ? a) Border Layout Manager
  • 8. b) Flow Layout Manager c) Grid Bag Layout Manager d) Card Layout e) None of the Above. • In which Layout Manager the container is divided into equally-sized rectangles, and one components is placed in the rectangles a. Border Layout Manager b. Flow Layout Manager c. Grid Bag Layout Manager d. Card Layout e. Grid Layout f. None of the Above. • Which of the following are the features of swing components? a. Lightweight b. Portable c. Look & Feel d. All the above • MVC stands for a. Model View Controller b. Model View Container c. Meta View Container
  • 9. d. Model Volatile Container • Swing components are categorized into a. Applets and Applications b. Frames and Panels c. Containers and Controls d. none of above • Window Event can be activated on the containers like a) JFrame b) JPanel c) Component d) Controls • The method used to alter the displayed set of characters in the components like password field is a. setText() b. setLabel() c. echoChar() d. setEchoChar() • The method used to add element in the combobox is a. addItem() b. addElement() c. addValue() d. setElement() • Which methods is used to separate different menu items in the menu bar
  • 10. a. addSeperator() b. add(“-“) c. addLine() d. displaySeperator()