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

Opps Java

The document provides an overview of topics related to object oriented programming in Java, including: 1) BASIC Java concepts like operators, data types, and method signatures 2) AWT and event-driven programming 3) Collections, exceptions, file handling, generics, inheritance, multithreading, and other core OOP concepts It contains examples and questions for each section to help reinforce learning.

Uploaded by

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

Opps Java

The document provides an overview of topics related to object oriented programming in Java, including: 1) BASIC Java concepts like operators, data types, and method signatures 2) AWT and event-driven programming 3) Collections, exceptions, file handling, generics, inheritance, multithreading, and other core OOP concepts It contains examples and questions for each section to help reinforce learning.

Uploaded by

Rutik Dak
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 68

USM’s Shriram Mantri Vidyanidhi Info Tech Academy

Object Oriented Programming with Java eDAC Sept 21

Contents

BASIC 1
method? 6
CLONE REFLECTION API 8
COLLECTION API 8
EXCEPTION 11
FILE HANDLING 19
GENERICS 23
INHERITANCE 24
JAVA FX 40
MULTITHREADING 41
OOPS 47
SOCKET PROGRAMMING 64

BASIC
1. What is the output of the following code?
inti = 16; intj = 17;
System.out.println("i >> 1 = " + (i >> 1)); System.out.println("j >> 1 = " + (j >> 1)); A.
Prints "i >> 1 = 8"
"j » 1 = 8"
B. Prints "i >> 1 = 7" "j » 1 = 7"
C. Prints "i >> 1 = 8"
>> 1 = 9"
D. Prints "i >> 1 = 7"
"j >> 1 = 8"

2. What is the output of the following code?


int i = 45678; intj = -i; system.out.println(j);
A. Compilation error at line 2-. ~ operator applicable to boolean values only.
B. prints 45677.
c. Prints -45677. D.
Prints -)45679.

3. What will happen when you invoke ‘the following method?


void infiniteLoop()
{
byte b = 1; while ( ++b > 0 ); System.out.println("Welcome to Java");
}
A. The loop never ends(infiniteLoop).
B. Prints "Welcome to Java". ‘
C. Compilation error at line 5. ++ operator should not be -~ used for byte type variables.
D. Prints nothing.
1
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21

4. What is the output for the following lines of code?


System.out.printin(“ " +2 + 3);
System.out.printin(2*+ 3); System.out.println(2 + 3 +"")-; system.out;println(2+””+3);
A. Compilation,error at line 3
B. Print s 23,6,5 ,2,3
C. Prints 5, 5, 5 and 23.
D. Prints 23, 5, 23 and 23.

5. What will happen if you compile/ run this code?


inti = 012; intj = 034; int k = 056; int l = 078;
System.out:println(i);
System.out.println(j);
System.out.println(k);
A.Prints12,34"and56. * ~
B. Prints 24,68 and 112.
C. Prints 10,28 and 46.
D. Compilation error

6. When executed the following line of code will print


System.out.println(-1 * Double.NEGAT|VE_|NFlNlTY);
A. –Infinity B. Infinity C. NaN D. –NaN

7.. Which of the following are the correct signatures for method main()?
A. public static void main()
B. public static int main(String arg[])
C. public static void main(String arg[])
D. public static void main(String args[])
E. private static void main(String args[])

8. Which of the following statements is/ are true? A.


Java provides automatic garbage collection.
B. The garbage collector is a low priority thread.
C. The method gc, when executed from a method, runs garbage collector.
D. If certain precautions are not taken, the garbage collector may collect some objects still in use.
E. You can force garbage collection of an object by setting all references to that object to null.

9. What is the size of a byte datatype?


A. -128 to 127
B. (-2 power 8 )-1 to 2 power 8
C. -255 to 256
D. depends on the particular implementation of the Java Virtual machine

10. Which line out of the following will compile without a warning or an error?
A. boolean b=null; B. float f=1.3; C. byte b=257; D. int i=10;

11. jvm Is
A. platform dependant B. platform lndepedent
2
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21

C. depends on jvm implementation D. Both b and c

12. return type of main method is


A. int B. char C. void D. None of the above

13. Garbage collection works on


A. heap B. queue C. tree D. None of the above

14. What will be printed out if you attempt to compile and run the following code int i=1; switch
(i)
{ case O:
System.out.prinUn("zero"); break; case 1:
System.out.println("one"); case 2:
System.out.prinUn("two"); default:
System.out.println("default");
}
A. One B. one, default C. one,two,default D. Default

15. If a local variables of a method shop() belonging to a class called Walmart has the same name as a
data member of Walmart, which value is used when shop() is executing?
A. the local variable’s B. the class variable’s
C. the data member’s D. None of the above since this would cause a compiler error

16. void main()


{
int k=35,*z,*y; z=&k; y=z *z =++*y; k++; printf("%d
%d”,k,++*z,*y++);
}

A. 363637 B. 383837 C. 373737 D. none of these

17. what is the output of the following c program:


int fun (int i)
{
printf(”in funtions int i");
}
void fun(int & i)
{
printf("in functions int& i”);
}
main()
{
int i=9;
fun(i)-;
}
A. ambiguity error B. in functions int& i C. in funtions int i

3
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21

D. syntax error E. runtime error

18. what will be the output of the following program? void


main()
{
char *s=”12345s\n\t”;
printf("%d”,sizeof(s)+str|en(s) );
}
A. 17 B. 14 C. 12 D. 10 E. 7

19. char *f()


{
char *s=(char*)ma||oc(8);
strcpy(s, "goodbye”);
return 5;
}
void main()
{
char *f();
printf(”%c”, *f()=’z’);
}
A. goodbye B. zoodbye C. g D. 10 E. Z

20. what will be the output of the following program?


main()
{
Int,I;
Unsigned num=71;
For(i=16;I;--i)
{
Printf(“%d”,(num<<i&1<<16)?1:0);
}
}
A. 0000000000010111 B. 1110001100000000
C. 1110001000000000 D. 01100000010000000

21. void main()


{
int y; unsigned int x=1; v="0; iflx==y) printf(”equa|”); else
printf(”not equal");
}
A. equal B. not equal C. compile time errortype mis-match
D. runtime E. compile time error |value required

AWT
1. Adapter class is not available for

4
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21

A. ItemListener B. MouseLIstener C. KeyListener D. WindowListener

2. Given public class MyApp extends Applet


{
public MyApp(int k)
{
}
}
What will happen to the above code?
A. compilation error “cannot instantiate MyApp”
B. runtime error “paint() method not available”
C. runtime error “InstantiationException”
D. compilation error “paint() not defined”

3. Given public class MyApp2 extends Applet


{
@Override
public void init() {
setLayout(new GridBagLayout());
GridBagConstraints gbc=new GridBagConstraints(); gbc.gridwidth=3;
gbc.gridheight=2; add(new Button("ok"));
}

}
What will happen?
A. compiler error “add method must take 2nd argument as GridBagConstraints”
B. exception during runtime
C. Button will appear according to gridwidth and gridheight specified
D. Button will appear but not according to gridwidth and gridheight specified.

4. Select correct statement from the following


A. BorderLayout is the default layout for Applet
B. GridLayout can not work without GridBagConstraints
C. pack() method displays window in a preferred size
D. FlowLayout can not be used for swing components

5. Given setLayout(new BorderLayout()); add("south",new TextField(20)); What will happen to the


above code?
A. compiler error
B. textfield will be displayed properly at south
C. exception
D. textfield will be displayed in the center,since u have given illegal argument.

6. Select the wrong statements from the following


A. Applet extends Panel B. FileDialog extends Dialog C. Dialog
extends Frame D. Window extends Container

5
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21
7. Given public class Trial extends Frame
{
public Trial(String mess)
{
MenuBar mb=new MenuBar();
// here
}
}
How will u add “mb” to the frame?
A. addMenuBar(mb); B. setMenuBar(mb); C. mb.addMenuBar(); D. add(mb);

8. Which method is required to read parameters pass to Applet?


A. getParameter B. getInitParameter C. getAppletParameter D. none of these

9. What is sent to the user via HTTP, invoked using the HTTP protocol on the user’s computer and run on
the user’s computer as an application?
A. A Java application B. A Java applet
C. A Java Servlet D. None of the above
10. java.awt.Component class method getLocation() returns Point (containg x and y cordinate).What does
this x and y specify
A. Specify the position of components lower-left component in the coordinate space of the component's
parent.
B. Specify the position of components upper-left component in the coordinate space of the
component's parent.
C. Specify the position of components upper-left component in the coordinate space of the screen. D.
None of the above

11. When u invoke “repaint()”, for a lightweight component , the AWT package calls which
component method?
A. repaint() B. update() C. paint() D. draw()

12. Which of the following the valid way to embed an applet class named myapplet into a web page.
A. <applet class=myapplet.class width=100 height=100> </applet>
B. <applet code=myapplet width=100 height=100> </applet>
C. <applet code=myapplet.class height=100 width=100 > </applet> D. <applet param=myapplet.class
width=100 height=100> </applet>

13. What is the purpose of “code” attribute of the applet tag? A.


A URL that points to the class of the applet.
B. A URL to the applet when it is stored in jar or zip file.
C. Indicate the base URL of the applet if the code attribute is relative.
D. Defines the horizontal spacing around the applet.

14. Executable applet is nothing but file of applet.


A. class B. java C. html D. applet

15. What does the following line of code do? TextField tf=new TextField(30);
A. This code is illegal , as there is no such constructor available inside “TextField” class.
6
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21
B. Creates the TextField object, that can hold 30 rows, but since it is not initialized to
anything, it will be always empty.
C. Creates a new TextField object that is 30 columns of text.
D. This code creates a TextField object that can hold 30 rows of text

16. Select correct statement from the following


A. Invisible components are required in SwingLayout
B. BorderLayout is the default layout for JApplet
C. The default lookandfeel for swing components is MotifLookAndFeel.
D. Swing does not have DelegationEvent model.

17. Method to apply menubar to the swing container is:


A. addMenuBar() B. setJMenuBar()
C. setSMenuBar() D. setMenuBar()

18. Select wrong statement from the following A.


FlowLayout is the default layout for Applet.
B. By default Frame is invisible.
C. pack() method displays window in a preferred size
D. None of these.
19. Given setLayout(new BorderLayout()); add(new TextField(20)); What will happen to the above code ?
A. compiler error
B. exception
C. textfield will not be displayed since u haven’t mentioned an area.
D. textfield will be displayed in the center.

20. Given import java.awt.*; public class MyFr2


{
Button b1,b2;
public MyFr2(String title)
{
Frame f=new Frame(title);
f.setLayout(new BorderLayout());
b1=new Button("ok"); b2=new
Button("cancel");
f.setLayout(new FlowLayout());
f.add(b1);
f.add(b2);
f.setSize(400,400);
f.setVisible(true);
}
public static void main(String args[])
{
new MyFr2("My Window");
}
}
What will happen to the above code ?
A. compiler error “can not set layout twice”
7
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21
B. frame will be displayed with only one “cancel” button
C. frame will be displayed with two buttons.
D. exception during runtime.

CLONE REFLECTION API


1) Cloneable interface contains “clone()” method
A. True B. False

2) Clone method is declared as throws


A. IOException B. CloneNotFoundException
C. CloneNotSupportedException D. None of the above

3) Clone() method in Object class is


A. Protected B. Public C. Default D.Private

4) If u override “clone()” method u can apply access modifier


A. Protected B. Public C. protected or public D. Default

5) By default “clone” method does


A. Shallow copy B. Deep copy C. Shallow and deep both copies 6) D. None
Interface which does not contain any method is called as
A. Empty B. Methodless C. Marker D. Void
7) Inner class methods can access outer class members directly
A. True B. False
8) Static nested class methods can access outer class members directly
A. True B. False

9) There is one instance of class “Class” per class loaded.


A. True B. False

10) To instantiate a particular class through reflection api we use


A. New Class B. Class.newInstance C. Class.newCreate D. None of the above

COLLECTION API
1. One of the following throws ConcurrentModificationException if we try to modify while iterating over it.
A: Hashtable B: CopyOnWriteArrayList
C: ArrayList D: ConcurrentHashMap

2. The default capacity and load factor for Map implementations are
A: 12 and 0.60 B: 16 and 0.75 C: 20 and 0.75 D: 18 and 0.60

3. Given
Class Animal{void eat(){}}
Class Dog extends Animal{}

8
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21
Class Cat extends Animal{}
Void disp(List<? super Dog> mylist)
Which of the following is the wrong argument to disp ?
A: ArrayList of Animal B: ArrayList of Dog
C: ArrayList of Object D: All the above are correct arguments.

4. Which statement is true ?


A: List<?> will allow u to add inside list. B: List<Object> will allow u to add inside list
C: both A and B D: we can pass ArrayList<Integer> to List<Object>

5. 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.utiI.HashSet B: java.utiI.LinkedHashSet
C: java.utiI.List D: java.util.ArrayList

6. Which of the following class uses String as key to store the value in object?
a) Dictionary b) Array c) ArrayList d) Properties

7. Which of these class objects uses key to store value?


a) Hashtable b) Dictionary c) Map d) all if the mentioned

8. can be used to control the order of certain data structure and collection of object too.
a) Serial comparators b) natural comparators
c) comparators d) all of the above

9. How does the set collection deal with duplicate elements?


A. An exception is thrown if you attempt to add an element with a duplicate value
B. The add method returns false if you attempt to add an element with a duplicate value

C. A set may contain elements that return duplicate values from a call to the equals method
D. Duplicate values will cause an error at compile time
10. What is the sequence followed by HashMap or HashSet while adding or retrieving entries.
A: ==, equals(), hashcode() B: equals(), == , hashcode() C: hashcode() , == , equals() D: none of
these

11. If you try to invoke “remove()” method on iterator of CopyOnWriteArrayList , it raises following
exception
A: ConcurrentModificationException B: UnsupportedOperationException C: IllegalOperationException
D: none of these

12. Map implementation which provides both Thread-Safety as well as Concurrency.


A: ConcurrentHashMap B: HashMap C: HashTable D: none of these

13. Stream API is used to implement


A: Internal iteration B. External iteration
C. Both A and B D. None of the above

9
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21
14. In get () or put() of map implementation equals () is Called before ==.
A. True B. False

15. Algorithms are present inside.


A. LinkedList B. Collection C. Collections D. Hashtable

16. Iterator of ArrayList is Fail-Safe.


A. False B. True

17. All the Collection API implementation classes implement .


A. Runnable B. Serializable
C. Externalizable D. Comparable

18. When you add any object inside Collection API implementation class, its copy is added.
A. True B. False

19. Whenever we create any implementation of set it result into .


A. Vector B. None of these C. List D. Map

20. In map implementation when hashcode of two keys are same it is called as?
A. Hashing B. Hash Collision C. Hash Clash D. None of these

21. One of the following allows us to define more than one strategies.
A. Comparator B. None of these C. Enumeration D. Comparable

22. Snapshot of list is created in case of .


A. CopyOnWriteArrayList B. Linked List C. Arraylist D. Vector

23. One of the followings is not Thread Safe


A. StringBuffer B. Hashtable C. Vector D. none of these

24. Suppose that you would like to create an instance of a new Map that has an iteration
order that is the same as the iteration order of an existing instance of a Map. Which concrete
implementation of the Map interface should be used for the new instance?
A. TreeMap B. HashMap C. LinkedHashMap

25.Which class does not override the equals() and hashCode() methods, inheriting them directly from class
Object?
A. java.lang.String B. java.lang.Double
C. java.lang.StringBuffer D. java.lang.Character

26.What will happen if you compile/run the folowing lines of code? Vector a = new Vector();
a.addElement(10);
System.out.println(a.elementAt(0)_);
A. Prints 10. B. Prints 11.
C. Compilation error at line 3. D. Prints some garbage.

Q.27 Comparable is a
1
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21

A. interface B. classes C. Both 1 and 2 D.none of the above

Q.28 Arraylist is
A. class B. List implementation
C. Both a and b D. None of the above

Q.29 hash code is used by


A. set B. map C. both a & b D. None of the above

Q.30 Which of the following data structures implements FILO mechanism


a) Queue b) Hash c) Linked List d) Stack

Q.31 Which of the following statements is true?


a) Hashmap is thread-safe while Hashtable is not
b) Hashmap is thread-safe while HashMap is not
c) Both are thread-safe
d) Both are not thread-safe

EXCEPTION
1. Given Following code: import java.io.*; class
sub extends base
{
void disp()throws IOException
{
}
}
class base
{
void disp()throws Exception
{
}
}
public class myclass
{
public static void main(String args[])
{ try
{
base b=new sub(); b.disp();
}
catch(Exception ee)
{
System.out.println(ee);
}
System.out.println(“done”);
}
}

1
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21
A. warning B. compilation error C. runtime error D. output
“done”

2. Which statement is false from the following?


A. we can have try and finally without catch
B. finally gets executed irrespective whether exception is raised or not
C. if system.exit is called from within try or catch, finally will not be executed at all D.
none of the above

3. Class.forName requires which of the following exception to be handled


A. ClassCastException B. ClassNotFoundException
C. IllegalAccessException D. none of the above

4. Class.newInstance() requires which of the following exception to be handled


A. IOException B. ClassNotFoundException
C. IllegalAccessException D. none of the above

5. Imagine there are two exception classes Exception1 and Exception2 derived from the Exception class.
Given these two definitions:
class First
{
void test()throws Exception1,Exception1
{
}
}
class Second extends First
{
void test()
{
}
}
Now define a class “Third” derived from “Second” and override “test ()” method inside it. What
exceptions can Third’s test() method throw?
A. Exception1 B. Exception2
C. No checked exceptions D. it can declare any checked

6. What letters get written to the standard output with the following code? public class MyClass
{
public static void main(String args[])
{ try
{
method();
}
catch(Exception ie)
{
}
}
static void method()
1
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21
{ try
{
wrench();
System.out.println("a");

}
catch(ArithmeticException ae)
{
System.out.println("b");
}
finally
{
System.out.println("c");
}
System.out.println("d");
}

static void wrench()


{
throw new NullPointerException();
}
}
A. A B. b C. c D. Compilation error

7. Which statement is false from the following?


A. The exceptions that are checked at compilation-time by the Java Compiler are called
B. ‘Checked exception’.
C. The exceptions that are checked by the JVM are called ‘unchecked exception D. Both 1 and 2
E. None of the above

8. Read the following code below. public interface AQuestion


{
public abstract void someMethod() throws Exception;
}
A Class implementing this interface should
A. Necessarily be an abstract class
B. Should have the method public abstract void someMethod();
C. Should have the method public void someMethod() which has to throw an exception which is a subclass of
java.lang.Exception.
D. Should have the method public void someMethod() which need not throw an Exception.

9. Given: public class Test


{
public static void throwIt()
{
throw new Exception();
}
public static void main(String[] args)
1
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21
{ try
{
System.out.println("Hey There");
} finally
{
System.out.println("in Finally");
} }}
What will happen when one tries to compile and run above code?
A. Compilation Fails
B. The program will print Hey There, then will print in finally.
C. The program will print Hey There, then will print that an Exception has occurred, and then will print in
finally.
D. None of them

10 Given:
1. public class Foo {
2. public static void main(String[] args) {
3. try {
4. return;
5. } finally {
6. System.out.println( "Finally" );
7. } 8. } 9. }
What is the result?
A. Finally B. Blank C. Null D. None of the above

11. In exception handling mechanism, finally block is always executed, even if no exception occurred in the try
block
A. True B. False

12. Exceptions can be caught or rethrown to a calling method.


A. True B. False

13. Given Following code: import java.io.*; class base


{
void disp()throws IOException
{
}
}
class sub extends base
{
void disp()throws Exception
{
}
}

public class myclass


{
public static void main(String args[])
1
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21
{

}
}
A. compile error
B. neither compilation nor runtime error
C. no compilation error but exception at runtime.

14. What will happen to the following code?


public class Test
{
public static void aMethod() throws Exception
{
try /* Line 5 */
{
throw new Exception(); /* Line 7 */
}
finally /* Line 9 */
{
System.out.print("finally "); /* Line 11 */
}
}
public static void main(String args[])
{ try
{
aMethod();
}
catch (Exception e) /* Line 20 */
{
System.out.print("exception ");
}
System.out.print("finished"); /* Line 24 */
} }
A: finally B: exception finished
C: finally exception finished D: compilation fails

15. Which statement is true,if the following program is run by java test10 ? public class test10
{
public static void main(String []args)
{
String []num={"one","two","three","four"}; if(args.length==0)
{
System.out.println("Zero");
}
else {
System.out.println(num[args.length]+" arguments”);
}

1
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Object Oriented Programming with Java eDAC Sept 21
}
}
A. The program won’t run because argument of main is not properly mentioned
B. The program will throw a NullPointerException
C. The program will display Zero when executed
D. The program will display 0 arguments when executed

16. following program will not print “==” public class test12
{
Public static void main(String args{})
{
String first=”abc”;
String second=new String(first);
If(first==second)
{
System.out.println(“==”);
}
}
}
A. True B. False

17. Assuming a method contains code which may raise an Exception (but not a RuntimeException), what is
the correct way for a method to indicate that it expects the caller to handle that exception:
A. throw Exception B. throws Exception
C. new Exception D. Don't need to specify anything

18. What is the result of executing the following code, using the parameters 4 and 0:
public void divide(int a, int b)
{ try {
int c = a / b;
}
catch (Exception e)
{
System.out.print("Exception ");
} finally
{
System.out.println("Finally");
}
A. Prints out: Exception Finally B. Prints out: Finally
C. Prints out: Exception D. No output

19. Given public class MyClass


{
public static void main(String args[])
{
String s1="hello";
String s2=new String("hello");
String s3="hello";
1
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
System.out.println(s1==s2);
System.out.println(s1==s3);
System.out.println(s1.equals(s2));
}
}
What will be the output ?
A. true, true, true B. true, false, true
C. false, true, true D. none of the above

20. specify which of the following is true ?


A. protected members can not be accessed directly in the same package.
B. Protected member can be accessed with super class reference in different package.
C. Private member can be accessed by subclass using super keyword.
D. Constructors are not inherited.

21Can you declare method local variable as final and can an abstract class may be final?
A. Yes, yes B. Yes, no C. No, yes D. No, no

22. Which of these methods of String class is used to obtain character at specified index?
A. char() B. charOn() C. charat() D. charAt()

23. What will happen in the below code snipet: public class MyClass
{
int i; float f; double d;
boolean bl;
public static void main(String args[])
{

System.out.println("int = "+i);
System.out.println("float = "+f);
System.out.println("double = "+d);
System.out.println("boolean = "+bl);
}
}
A. Int=0 float=0.0 double=0.0 boolean=false
B. Compilation error: cannot make static reference to the non-static field
C. Int=0 float=0.000 double=0.000 boolean=false
D. Compilation error: variable may not have been initialized

24. What is legal?


A. Try{}catch() B. Try{}catch()finally{}
C. Try{}finally{} D. All of the above

25. What will be returned?


Try{return 1;}catch(){return 2;}finally{return 3;}
A. 3 B.2 C.1 D. Compilation error

26. One of the following is unchecked exception


1
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
A. IOException B. ClassNotFoundException
C. FileNotFoundException D. None of the above

27. Which one is checked exception


A. ClassCastException B. MalformedURLException C. ArrayIndexOutOfBoundsException D. None of
the above

28. In order to declare exception which keyword is used


A. Throw B. Throws C. Throwing D. None of the Above

29. when an exception happens in the finally block it should be


A. It should be thrown by using throws. B. We should catch it
C. Depends on scenario D. None of the above.

30. Checked exceptions are automatically propagated to the caller.


A. True B. False

31. Unchecked exceptions are automatically propagated to the caller.


A. True B. False

32. If u want to create checked exception as user defined exception u need to extend
A. RuntimeException B. Throwable C. Exception D. Error

33. When u write one try and multiple catch the most specific catch should precede the most generic catch
A. True B. False

34.34.
class exception_handling
{
public static void main(S1ring argsO)
{
try
{
System.out.print("Hello" + " " + 1IO) ;
} finally
{
System.out.print("World");
}
}
}
A. Hello B. World
C. Compilation Error D. First Exception then World

36. Which of the following is not generally recoverable in the program


A. Error B. Exception C. Both a and b D. None of the above.

1
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
FILE HANDLING
1. One of the following class provides “seek ()” method
A: FileInputStream B: File C: RandomAccessFile D: FileReader

2. Given
File f=new File("abc.txt");
FileInputStream fis=new FileInputStream(f); byte arr[]=new byte[100]; which statement
will read content of “abc.txt” into arr.
A: arr=fis.read() B: f.read(arr) C: arr=f.read() D: fis.read(arr)

3. Which one is wrong statement?


A: FileInputStream fis=new FileInputStream(new BufferedInputStream("abc.txt"));
B: DataOutputStream dis=new DataOutputStream(new FileOutputStream("xyz.txt"));
C: FileOutputStream fos=new FileOutputStream(new File("aaa.txt"));
D: SequenceInputStream ss=new SequenceInputStream(new
FileInputStream("a.txt"),new
FileInputStream("b.txt"));

4. Given class base


{
int k;
}
class sub extends base implements Serializable
{
int j;
}
If we try to serialize instance of sub class,
A: sub as well as base state will be serialized
B: NotSerializableException
C: only sub instance will be serialized
D: compiler error “cannot serialized object having non-serializable parent”

5. Classes that do not implement interface will not have any of their State serialize or deserialized.
A: List B: SingIeThreadModeI C: Serializable D: Comparable

6. Which one of the following is not from java.io.package


A. String - correct ans B. StringReader C. Writer D. File

7. What is the output?


public static void main(String[] args) {
// TODO Auto-generated method stub int x=0; int y=10;
do {
y--; ++x;
}while(x<5);
System.out.println(x+"\t"+y);
} output- 5 5 how does readObject() of ObjectInputStream
indicate end of file?

1
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
A. returns null B. "" -1
C. throws java.io.EOFException - correct ans D. closes automatically

8. What does the following code do?


File f=new File(“hello.test”);
FileOutputStream fos=new FileOutputStream(f);
A. Create a file “hello.test” if it does not exists in write mode.
B. Open a file named “hello.test” , so that u can write to it and read from it but does not create the file if it
is not existing yet.
C. Open a file named “hello.test” , so that u can write to it and read from it.
D. Create an object that you can now use to create and open the file named “hello.test” and write to and
read from the file.

9. Given this code: Import java.io.*;


Class Write
{
Public static void main(String args[])
{
File f=new File(“a.txt”);
FileOutputStream fos=new FileOutputStream(f);
// write int here inside the file
}
How can u replace the comment at the end of main with code that will write integers from 0 to 9 ? A.
DataOutputStream dos=new DataOutputStream(fos);
a. for(int i=0;i<=9;i++)
b. {
i. dos.write(i);
c. }
B. for(int i=0;i<=9;i++)
a. {
i. f.writeInf(i);
b. }

C. for(int i=0;i<=9;i++)
i. {
i. fos.writeInt(i);
ii. }
D. DataOutputStream dos=new DataOutputStream(fos);
a. for(int i=0;i<=9;i++)
{
dos.writeInt(i);
}

10. What is the permanent effect on the file system of writing data to a new FileWriter("report"), given the
file report already exists?
A. The data is appended to the file
B. The file is replaced with a new file
C. An exception is raised as the file already exists
2
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
D. The data is written to random locations within the file

11. Which one is wrong statement?


A: FileInputStream fis=new FileInputStream(“abc.txt”);
B: DataOutputStream dis=new DataOutputStream(new FileOutputStream(“xyz.txt”));
C: FileOutputStream fos=new FileOutputStream(new File(“aaa.txt”));
D: FileOutputStream fos=new FileOutputStream(new ObjectOutputStream(“aaa.txt”));

12. Which statement is correct?


A: Externalizable is a base interface of Serializable
B: String class is final hence cannot be serialized
C: When a class implements Serializable and it is deserialized using readObject(), constructor is never
invoked.
D: Externalizable is a marker interface.

13. Given
class base
{
int k;
}
class sub implements Serializable
{
base b=new base();
int j;
}
If we try to serialize instance of sub class,
A: sub as well as base state will be serialized
B: NotSerializableException
C: only sub instance will be serialized
D: compiler error “ cannot serialized object having non-serializable parent”

14. Which class is not serialized


A: java.lang.Thread B: java.lang.Applet
C: java.lang.Class D: All of the above

15. is a communication path bet’n source and destination


A. File B. stream C. directory D. none of the above

16. InputStream and OutputStream are concrete classes


A. True B. false

17. if u want to write primitive types u need to use


A. DataoutputStream B. FileOutputStream
C. OutputStream D. ObjectOutputStream

18. class allows us to write and read both.


A. FileReaderWriter B. RandomAccessFile

2
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
C. BufferedWriter D. none of the above

19. Serializable extends Externalizable


A. True B. false

20. Serializable is marker interface.


A. True B. false

21. In case of Serializable when u deserialize an object constructor does not get invoked.
A. True B. false

22. While deserialization if serialversionUID does not match we get


A. IllegalClassException B. InvalidClassException
C. NullPointerException D. none of the above

23. Which is correct


A. FileOutputStream fos=new FileOutputStream(object to be added); ObjectOutputStream
oos=new ObjectOutputStream("filename"); oos.writeObject();

B. FileOutputStream fos=new FileOutputStream("filename");


ObjectOutputStream oos=new ObjectOutputStream(object to be added); oos.writeObject();

C. FileOutputStream fos=new FileOutputStream("filename"); ObjectOutputStream oos=new


ObjectOutputStream(fos); oos.writeObject(object to be added);

D. none of the above

24. File class is used to create new file.


A. True B. false

25. in case of Externalizable when u deserialize an object first readExternal() is called and then constructor
is called.
A. True B. false

26. In order to serialize inner class, outer class must be Serializable


A. True B. false

27. If inner class implements Externalizable we don’t get any problem while deserialization A. True
B. false

28. If static nested class implements Externalizable we don’t get any problem while deserialization
A. True B. false

29. Java.lang.Object class implements Serializable


A. True B. false

30. transient variables make sense I n context


A. inheritance B. Association C. Serialization D. None of the above
2
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy

31. Which of these classes are used by character streams for input and output operations?
A. lnputStream B. Writer C. ReadStream D. lnputOutputStream

32. FileWriter fw =new FileWriter("a.xyz"); in this code, we are using


A. Text based io B. binary based 10 C. both a and b D. none of the above.

GENERICS
1. At the time of compilation compiler removes all the information about generics. This is known as A.
Generic-removal B. Generic-Erasure C. Type-Erasure D.none of the above

2. <P extends Q> here Q can be either class or interface


A. True B. false

3. We can’t have generic method in non-generic class


A. True B. false

4. Polymorphism applies to base type as well as generic type.


A. True B. false

5. Mixing generic and non-generics can be risky


A. True B. false

6. If the base class reference referring to sub class array then there is a possibility of
A. IllegalArrayException B. ArrayStoreException
C. NullPointerException D. none of the above

7. In case of <? Extends ……> we can add


A. True B. false

8. In case of <? super ……> we can add


A. True B.false

9. List<? Super Thread> mylist=new ArrayList<Object>() will work


A. Yes B. no

10. List <? Super Dog> mylist=new ArrayList<Animal>() mylist.add(new Cat()); will work
A. Yes B. no

11. List<?> allows u to add


A. True B. false

12. List<Object> allows u to add


A. True B. false

2
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
INHERITANCE
1. What is the output of following code.
class a
{
static
{
System.out.println(" static a");
}
}
class b extends a
{
static
{
System.out.println(" static b");
}
}
class c extends b
{
static
{
System.out.println(" static c");
}
}
public class myclass
{
static
{
System.out.println(" static myclass");
}
public static void main(String args[])
{
new c();
System.out.println("in main");
}
}

A: in main, static a,static b,static c, static myclass


B: static myclass, static a,static b,static c, in main
C: static myclass, in main ,static a,static b,static c
D: static a,static b,static c, static myclass, in main

2. What will happen to the following code ?


class base
{
public final void disp ()
{
System.out.println (“in disp”);

2
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
}
}
public class sub extends base
{
public static void main (String argv [] )
{
base b = new base() ; b.disp
();
}
}
A: runtime error
B: compiler error “final method must be inside final class”
C: compiler error “a class having final method can not be inherited”
D: neither compilation nor runtime error

3. what will be the output ? class


base
{
int i; base()
{
add(1);
}
void add(int v)
{ i+=v;
}
void
print()
{
System.out.println(i);
}
}
class sub extends base
{
sub()
{
add(2);
}
void add(int v)
{
i+=v*2;
}
}
public class test6
{
static void disp(base b)
{
b.add(8);
b.print();
2
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
}
public static void main(String args[])
{
disp(new sub());
}
}
A: 9 B: 18 C: 22 D: 21

4. What is the output of following code ? interface emp


{
}
public class Trial implements emp
{
public static void main(String args[])
{
Trial t=new Trial();
if(t instanceof Trial)
{
System.out.println("Trial");
}
if(t instanceof emp)
{
System.out.println("emp");
}
if(t instanceof Object)
{
System.out.println("Object");
}
}
}

A: Trial, emp, Object


B: Trial, emp
C: compilation error “can not use instanceof with interface”
D: Trial, Object

5. what is the output of the following code?


class a
{
static
{
System.out.println("static a");
}
}
class b extends a
{
static
{
2
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
System.out.println("static b");
}
}
class c extends b
{
static
{
System.out.println("static c");
}
}
public class MyClass
{
static
{
System.out.println("static MyClass");
}
public static void main(String args[])
{
new
c();
System.out.println("in main");
}
}
A. in main, static a, static b, static c, static MyClass
B. static MyClass, static a, static b, static c, in main
C. static MyClass, in main, static a, static b, static c
D. static a, static b, static c, static MyClass, in main

6. what will happen to the following code? class base


{
public final void disp()
{
System.out.println("disp");
}
}

public class sub extends base


{
public static void main(String args[])
{
base b=new base(); b.disp();
}
}
A. runtime error
B. compiler error: final method must there in final class
C. compiler error: a class having final method can not be instantiated.
D. Neither compile time nor runtime error.

2
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
7. Why multiple inheritance is not available in java?
A. It leads to confusion for a Java program
B. The programmer can achieve multiple inheritance by using interface
C. The programmer can achieve multiple inheritance by repeatedly using single inheritance D.All of
the above

8. what is the output? class base


{
}
class sub1 extends base
{
}
class sub2 extends sub1
{
}
class sub3 extends sub2
{
}
public class test12
{
public static void main(String args[])
{
sub1 s=new sub2(); base b=s;
if(b instanceof base)
{
System.out.println("base");
}
if(b instanceof sub1)
{
System.out.println("sub1");
}
if(b instanceof sub2)
{
System.out.println("sub2");
}
if(b instanceof sub3)
{
System.out.println("sub3");
}

}
}
A. base B. sub3 C. sub1 D. sub2

9. Given the following code,what can be said about the statement s=(sub)b ? class base
{
}
class sub extends base
2
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
{
}
public class test12
{
public static void main(String args[])
{
base b=new base(); sub s=new sub();
s=(sub)b;
}
}
A. legal at compile time but illegal at runtime
B. illegal at compile time
C. legal at compile and runtime ,but (sub) cast is not needed D. legal at compile and runtime ,but (sub)
cast is strictly needed.

10. What will happen when you attempt to compile or run this code? class Base
{
public final void amethod ()
{
system.out.println (“amethod”);
}
}
public class Fin extends Base
{
public static void main (String argv [] )
{
Base b = new Base() ; b.amethod
() ;
}
}
A. Compile time error indicating that a class with any final methods must be declared final itself
B. Compile time error indicating that you inherit from a class with final methods.
C. Run time error indicating that Base is not defined as final.
D. Success in compilation and output of “amethod” at run time

11. class Foo


{
int num;
Bar comp=new Bar();
}
class Bar
{
boolean flag;
}
class Baz extends Foo
{
Bar thing=new Bar();
double d;
2
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
}

A. A Bar is a Baz B. A Foo has a Bar C. A Baz is a Foo D. A Foo is a Baz


E. A Baz has a Bar.

12. What will happen to the following code? interface X


{
static void disp()
{
System.out.println("in disp of X");
}
}

public class Trial implements X


{
public static void main(String args[])
{
Trial t=new Trial(); t.disp();
}
}
A. Compilation error “disp not available with Trial”
B. Compilation error “static method can not be defined inside an interface”
C. Compilation error “ Trial class must define disp as it is there inside parent interface” D. Output “ in
disp of X”

13. Given interface emp //


functional interface
{
String wish(String name);
}
Lambda expression in order to use above interface would be:
A. emp ref2=(String name)->{ return "Welcome to our site\t"+name;};
B. emp ref2=(String name){ return "Welcome to our site\t"+name;};
C. Both A and B
D. None of the above

14. How restrictive is the default accessibility compared to public, protected and private accessibility? a.
Less restrictive than public.
A. More restrictive than public, but less restrictive than protected
B. More restrictive than private
C. More restrictive than protected, but less restrictive than private
D. Less restrictive than protected from within a package, and more restrictive than protected from outside
a package

15. What will be the output of the following code? public class VerySmart
{
public static void main(String[] args)

3
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
{
String message;
System.out.println("message length is : " + message.length() );
}
}
A. /0 B. 0 C. compile time error D. run time error

16. The programmer must explicitly create the System.in and System.out objects.
A. True B. False

17. A method within a class is only accessible by classes that are defined within the same package as the
class of the method. How can such a restriction be enforced?
A. Declare the method with the keyword “public”
B. Declare the method with the keyword “protected”
C. Do not declare the method with any modifiers.
D. Declare the method with the keyword “private”
E. Declare the method with the keyword “package”

18. A final class cannot have any abstract methods.


A. True B. False

19. String class is


A. final B. abstract C. static D. transient

20. what is the result of following code ? class base


{
int i;
base()
{
add(1);
}
void add(int v)
{ i+=v;
}
void print()
{
System.out.println(i);
}
}
class sub extends base
{
sub()
{
System.out.println(“in sub def const”);
super.add(2);
}
void add(int v)

3
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
{
i+=v*2;
}
}
public class test11
{
public static void main(String args[])
{
base b; b=new sub(); b.print();
}
}
A. 4 B. 3 C. Error: super has to be on first line of constructor D. 2

21. What is garbage collection process in java?


A. The operating system periodically deletes all the java files available on the system.
B. Unused package in program is automatically deleted.
C. When all references to an object are gone, memory used by that object is automatically reclaimed.
D. The JVM checks the output of any java program and deletes anything that does not make sense.

22. Given the following code, public class Test


{
String str="hello";
}
1. Test t=new Test();
2. System.out.println(t.str);
3. t=null;
4. System.out.println(t.str);
5. System.out.println("done"); What will happen to the above code?
A: “NullPointerException” at Line 3 B: “NullPointerException” at Line 4
C: Compilation error at Line 4 D: Successful out

23. Given the following code, public class Test


{
String str="hello";

}
6. Test t=new Test();
7. System.out.println(t.str);
8. t.str=null;
9. t=null;
10. System.out.println("done");
At which line the object created at 1 will be marked for garbage collection?
A: Line 3 B: Line 4 C: Can’t say exactly when D: both Line3 and Line4

24. What is the output?


public class Trial
{

3
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
int num=10;
void change(Trial ref)
{ ref.num=20;
ref=new Trial();
ref.num=30; ref=null;
}
public static void main(String args[])
{
Trial t=new Trial(); t.change(t);
System.out.println(t.num);
}
}
A: 30 B: 20 C: NullPointerException D: 10

25. class Bar { }


class Test
{
Bar doBar()
{
Bar b = new Bar(); /* Line 6 */ return b; /* Line 7 */
}
public static void main (String args[])
{
Test t = new Test(); /* Line 11 */
Bar newBar = t.doBar(); /* Line 12 */ System.out.println("newBar"); newBar = new Bar(); /*
Line 14 */
System.out.println("finishing"); /* Line 15 */
}}
At what point is the Bar object, created on line 6, eligible for garbage collection?
A. after line 12 B. after line 14
C. after line 7, when doBar() completes D. after line 15, when main() completes

26. What is the output for the following program?


class A
{
static
{
System.out.println("in A static block");
}
}
public class Trial
{
A ob=new A();
public static void main(String args[])
{
System.out.println("in main");
}
static
3
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
{
System.out.println("in Trial static block");
}
}

A: in A’s static block, in Trial static block, in main B:


in Trial static block, in main
C: in A’s static block, ,in main ,in Trial static block
D: in Trial static block, in A’s static block, in main

27. Given following code, what will happen to it ?


String str1="hello";
String str2="hel"; String str3=str2+"lo";
if(str1==str3)
{
System.out.println("str1 and str3 are==");
}
els
e
{ System.out.println("str1 and str3 are not ==");

if(str1.equals(str3))
{
System.out.println("str1 and str3 are equals");
}
els
e
{ System.out.println("str1 and str3 are not equals");

}
A: str1 and str3 are ==, str1 and str3 are equals
B: str1 and str3 are not ==, str1 and str3 are equals
C: str1 and str3 are ==, str1 and str3 are not equals
D: compilation error

28. Java supports


A. single level inheritance B. multi-level inheritance
C. hierarchical inheritance D. all of the above

29 Super must be on first line if we want to invoke base class constructor.


A. True B. False

30. Super need not be on first line if we want to invoke base class method.
A. True B. False

3
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
31 <default> is more accessible than protected.

3
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
A. True B. False

32. Final keyword can be applied to


A. Instance member B. Class variable C. Local variable D. All of the above

33. In java we can apply static modifier for local variable.


A. True B. False

34. In order to make a class abstract:


A. Apply abstract keyword to class B. Declare abstract method inside class
C. Both a and b D. None of the above

35. In order to check “is-a” relationship, we use following operator


A. Is-a B. Instanceof C. Is_relationship D. None of the above

36. If we try to cast the classes out of hierarchy we get


A. BadCastException B. OutOfHierarchyException
C. ClassCastException D. None of the above

37. At the time of overriding function, if we change the argument :


A. It gives compiler error B. It gives runtime error
C. Compiler automatically removes the argument D. It becomes overloading.

38. Will following code work? Class MyClass extends String{}


A. Yes B. No

39. Which of the following statements are true?


A. An abstract class may not have any final methods.
B. A final class may not have any abstract methods.
C. Every class must have a main method.
D. The mandatory elements in a file are: package, import and class.
E. A Java identifier must begin with a letter, $, ! or _.

40. super call should always be


A. main function B.in the super class C. in the subclass. D.None of the above

41. extends keyword can be used with


A. lnterface B. class C. both D. None of the above

42. final keyword for class in java means


A. no overriding B. no overloading C. Both a & b D.none of the above

43. interfaces in java is for


A. contract B. abstraction C. both a and b D. None of the above

45. The job that is done by the thread is decided by

3
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
A. run method B. start method C. main method D. None of the above

46. overriding uses


A. variables B. functions C. classes D. None of the above

47. class
A
{
int i;
void display()
{
System.out.println(i);
}
}
class B extends A { int j;
void display() { System.out.println(j));
}
}
class inheritance_demo {
public static void main(Stri111g argsO)
{
B obj = new B();
obj.i=1; obj.j=2;
obj.display();
}
}
Output of this program is
A.O B. 1 C. 2 D. Compilation Error

48. interface Z extends A, here A is


A. class B. function C. interface D. none of the above.

49. How can we ensure that a class will not be inherited from?
A. Delare it as constant B. Declare it as final
C. Declare it as static D. None of the above

50. superclass ref =new SubclassObject(),cannot access typically


A. Non final functions of super class B. Final functions of super class
C. Exclusive functions of sub class D. None of the above.

Q.51 When a program class implements an interface,it must provide behavio


A.Two methods defined in that interface. B. Only certain methods in an interface
C. Any methods in a class. D. All methods defined in that interface.

52. Which modifier would be used to limit the methods visibility to only the ot the current oackaae and all
subclasses.

3
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
A. public B. private C. protected D. default

53. The variables in an interface can have which modifiers?


A. Public B. Static C. Final D. All of the above

54. To compare whether two references point to the same object we use
A. == operator B. equals function C. we can use both D. none of the above.

55. non final functions have to be


A. overridden B. may be overridden C. ABoth a and b D. None of the above

56. What is the output of this program?


class A
{
Public int i;
Private int j;
}
Class B extends A
{
Void display()
{
super.j = super.i + 1;
System.out.println(supper.i + “ “ + supper.j);
}
}
class inheritance
{
public static void main (String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
A. 22 B. 33 C. Runtime Error D. Compilation Error

57. A class can be declared as if you do not want the class to be subclassed. Using the
keyword we can abstract a class interface from its implementation
A. protected, interface B. final, interface C. public, friend D. final, protected

58. Select the correct statement


A. Method overloading is called compiled time polymorphism
B. Method overloading is called runtime polymorphism
C. only [B] is correct
D. Both [A] and [B] are correct

3
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
59. What is the output of the below program?
public class A
{
public void foo()
{
System.out.println(“foo”);
}
public void foo(int a)
{
System.out.println(“foo(int)”);
}
}
public class B extends A
{
public void foo()
{
foo(5);
}
public void foo(int a)
{
System.out.println(“fooB(int)”);
}
}
public class test
{
Public static void main(String[] args)
{
A a = new B() ; a.foo()
;
}
}
A. Program will not compile B. fooB(int) C. foo(int) D. foo

60. What is the output of the below program ?


Public class A
{
Public int a1 = 5;
Public int a2 = 6;
Public static int a3 = 7;
Public static int a4 = 8;
Public void foo()
{
System.out.println(a1);
}
Public static void foo(int a)
{
System.out.println(a2);
}

3
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
}
Public class B extend A
{
Public void foo()
{
System.out.println(a3);
Foo(5);
System.out.println(a2);
}

A. 5
B. 7
6
8
C. 6
D. Program will not compile

61. What is the output of the below program?


Public class A
{
Public int a1 = 5;
Public int a2 = 6;
Public static in b1 = 7;
Public static int b2 = 8;
Public void foo()
{
System.out.println(getClass().getName());
}
Public void foo(int a)
{
System.out.println(getClass().getName());
}
}
Public class B extend A
{
Public void foo(int a, int b)
{
foo(a);
System.out.println(getClass().getName());
}
}
Public class Test
{
Public static void main(String[] args)
{
A a= newB();
a.foo();
}
4
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
}
A. program will not compile B. A C. B D. A B

62. Which of the following statements are true?


i. An instance of an abstract cannot be created ii .An
abstract class must have at least one abstract method iii.
An abstract class cannot implement an interface
A. i B. i , ii C. i , ii , iii D. ii

63. What will be the output of the following


program? Public class A
{
Public A()
{
this(5);
System.out.println(“A()”);
}
Public A(int a)
{
System.out.println(“A(int)”);
}
}
Public class B
{
Pulic B()
{
System.out.println(“B()”);
Super();
}
}
Public class Test
{
Public static void main(String[] args)
{
A a1 = new B();
}
}
A. program will not compile B. B() A(int) A() C. B() D. B() A() A(int)

JAVA FX
1. In JavaFX following class is acting as a container for all the contents
A. Scene B. Stage C. LayoutPane D.None of the above

2. In order to start every JavaFX application you must invoke following method
A. Init() B. Start() C. Launch() D. None of the above

4
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy

MULTITHREADING
1. One of the following method is not executed by the programmer while writing multithreaded
applications.
A: start B: sleep C: join D: run

2. Given public class Trial extends Thread


{
public void run()throws NullPointerException
{
System.out.println("hello");
}
public static void main(String args[])
{
new Trial().start(); System.out.println(“done”);
}
}

A: NullPointerException during runtime


B: Compilation error “overridden method does not throw NullPointerException”
C: output “done” “hello”
D: it will print “done” and then throw “NullPointerException”

3. Which of the following is the wrong statement


A: you cannot notify a particular thread
B: synchronized keyword can be applied to static methods
C: wait,notify methods can be called only from synchronized methods or block D:
InterruptedException is unchecked exception.

4. The interface should be implemented by any class whose instances are intended to be
executed by a thread.
A: Serializable B: Comparable C: Collection D: Runnable

5. Consider the following: class X implements Runnable


{
public static void main(String args[])
{
/* Missing code? */
}
public void run() { }
}

Which of the following lines 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();

6. Which of the following statements is true?


4
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
A: A static method cannot be synchronized
B: Non-synchronized method can become synchronized if it’s being called from a synchronized method
C: When a thread call wait() from a synchronized method, it releases the lock
D: Primitive variables can be protected from concurrent access using synchronized block.

7. Given
public class TestOne {
public static void main (String[] args) {
Thread.sIeep(3000);
System.out.printIn("sleep");
}
}
A: No error, prints sleep B: Compilation error
C: Runtime Error D: No error & no output

8. Which of the following are methods of the Runnable interface?


A: run B: start C: yield D: stop

9. While using Thread, which is incorrect


A. u invoke run() B. u invoke start()
C. u implement Runnable D. u extend Thread

10. Which type of instanceof does targetObject have to pass for this to be legal while using
Thread t=new Thread(targetObject);
A. targetObject instanceof Thread B. targetObject instanceof Applet
C. targetObject instanceof Object D. targetObject instanceof Runnable

11. are utilized to control the access to an object especially in multithreaded programming?
A. Asynchronized methods B. serialized methods
C. synchronized methods D. both a and c

12. means each method in multithreaded environment doesn’t access data by multiple
threads at the same time.
A. Thread detach B. thread isolation C. thread safety D. thread lock

13. Which of the following starts the default thread available in java program?
A. System class B. main method C. static keyword D. none of these
14. Which two can be used to create a new Thread?
A. Extend java.lang.Thread and override the run method.
B. Extend java.lang.Runnable and override the start method.
C. Implement java.lang.thread and implement the run method.
D. Implement java.lang.Runnable and implement the run method.

15. What is the use of the synchronized keyword?


A. Allows two process to run in parallel but to communicate with each other
B. Ensures only one thread at a time may access a method or object

4
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
C. Ensures that two or more processes will start and end at the same time D. Ensures that
two or more Threads will start and end at the same time

16. What will happen when you attempt to compile and run the following code?
public class Bground extends Thread
{
public static void main(String argv[])
{
Bground b = new Bground(); b.run();
}
public void start()
{
for (int i = 0; i<10; i++)
{
System.out.println("Value of i = " + i);
}
}
}
A. A compile time error indicating that no run method is defined for the Thread class
B. A run time error indicating that no run method is defined for the Thread class
C. Clean compile and at run time the values 0 to 9 are printed out
D. Clean compile but no output at runtime

17. Given the following,


1. class MyThread extends Thread {
2.
3. public static void main(String [] args) {
4. MyThread t = new MyThread();
5. t.start();
6. System.out.print("one. "); 7. t.start();
8. System.out.print("two. ");
9. }
10.
11. public void run() {
12. System.out.print("Thread ");
13. }
14. }
What is the result of this code?
A. Compilation fails
B. An exception occurs at runtime. java.lang.IllegalThreadStateException
C. Thread one. Thread two.
D. The output cannot be determined

18. What is the o/p of the following program?


1. class MyThread extends Thread {
2.
3. public static void main(String [] args) {
4. MyThread t = new MyThread();
4
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
5. Thread x = new Thread(t); 6. x.start(); 7. }
8.
9. public void run() {
10. for(int i=0;i<3;++i) {
11. System.out.print(i + "..");
12. } 13. }
14. }
A. Compilation fails. B. 1..2..3.. C. 0..1..2..3.. D.0..1..2..

19. In case of class lock, non-static synchronized methods come into picture.
A. False B. true

20. Sleep releases the lock whereas wait does not.


A. True B. False

21. What is the effect of issuing a wait () method on an object


A. If a notify() method has already been sent to that object then it has no effect
B. The object issuing the call to wait() will halt until another object sends a notify() or notifyAll() method
C. An exception will be raised
D. The object issuing the call to wait() will be automatically synchronized with any other objects using the
receiving object.

22. One of the following method has to be invoked by the programmer in order to bring thread from born
to runnable state.
A: start B: sleep C: join D: run

23. Which of the following is the correct statement


A: you can not notify a particular thread
B: synchronized keyword can be applied to static methods
C: wait,notify methods can be called only from synchronized methods or block D:
all of the above.

24. Select the correct statement:


A. in case of intrinsic lock, when exception is raised in a synchronized code, lock is
automatically released.
B. in case of Reentrant lock, when exception is raised lock is automatically released.
C. Both A and B.
D. None of these.

25. Threads are lightweight as compare to processes


A. True B. false

26. The method used to register thread with JVM scheduler


A. urn B. register C. start D. none of the above

27. By default the priority of thread is


A. Minimum B. maximum C. normal D. none of the above

4
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy

28. Sleep releases the lock wait does not


A. True B. false

29. One of the following methods programmer never invokes in case of multi-threading application
A. Run B. start C. wait D. notify

30. We can invoke wait, notify or notify all from non-synchronized methods
A. True B. false

31. What will happen?


public class MyThread extends Thread
{
@Override
public void start()
{
}
public static void main(String args[])
{
MyThread m1=new MyThread(); m1.run();
}
}
A. Compile time error B. Exception during runtime
C. No error no output D. Program will behave differently on different platforms

32. Wait, notify and notifyAll methods are


A. Abstract B. static C. final D. none of the above

33. All the blocking methods i.e. sleep, wait and join can throw
A. IllegalMonitorStateException B. InterruptedException
C. BlockingException D. none of the above

34.What will happen?


class MyTarget implements Runnable
{
public void run()
{
System.out.println(“MyTarget run”);
}
}
public class MyApp
{
public static void main(String args[])
{
MyTarget m=new MyTarget(); Thread t1=new Thread();
t1.start();

4
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
}
}
A. Output “MyTarget run” B. No output
C. Compilation error D. IllegalMonitorException during runtime

35. What will happen?


class MyTarget implements Runnable
{
public void run()
{
System.out.println(“MyTarget run”);
}
}
public class MyApp
{
public static void main(String args[])
{
MyTarget m=new MyTarget();
Thread t1=new Thread();
t1.start(m);
}
}
A. Output “MyTarget run” B. No output
C. Compilation error D. IllegalMonitorException during runtime

36. What will happen?


class MyTarget implements Runnable
{
public void run()
{
System.out.println(“MyTarget run”);
}
}
public class MyApp
{
public static void main(String args[])
{
MyTarget m=new MyTarget(); Thread t1=new Thread(m); t1.start();
}
}
A. Output “MyTarget run” B. No output
C. Compilation error D. IllegalMonitorException during runtime

37. A class which contains non-static synchronized methods or blocks is called as


A. Singleton B. Synchronized C. Thread-Safe D. none of the above

38. method makes caller thread wait till this thread die.
A. Wait B. sleep C. yield D. join
4
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
39. The job that is done by the thread is decided by
A. run method B.start method C.main method D.None of the above

40. in a function, the code


Thread.Sleep(1000); is showing a compilation error, because of Interrupted Exception, not being handled,
that means Interrupted Exception is
A. Runtime Exception B. Non Runtime Exception
C. Could be a or b D. None of the above.

41. class A extends


Thread
{
private int i; public
void run()
{ i= 1;
}
public static void main(String[] args)
{
A a = new A(); a.start();
System.out.print(a.i);
}}
What are the possible results of attempting to compile and run the program
A. Prints nothing B. Prints: 0 C. Prints: 1 D. Cant say.

39.class multithreaded_progr.aming
{
public static void main(String argsO)
{
Thread t = Thread.currentThread(); System.out.println(t);
}
}
This will call the toString method of
A. Thread class B. Object class C. String class D. none of the above

OOPS
1. What is the output?
public class Trial
{
int num=10;
void change(Trial ref)
{
ref.num=20;
ref=null;
}

4
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
public static void main(String args[])
{
Trial t=new Trial(); t.change(t);
System.out.println(t.num);
}
}
A: 20 B: 10 C: NullPointerException D: None of the above

2. Which of the following modifiers can be applied to Top Level classes?


A: public B: default C: protected D: both A and B

3. Which is true about an anonymous inner class?


A. It can extend exactly one class and implement exactly one interface.
B. It can extend exactly one class and can implement multiple interfaces.
C. It can extend exactly one class or implement exactly one interface.
D. It can implement multiple interfaces regardless of whether it also extends a class.

4. Local inner class cannot access


A: outer class member
B: its own static member
C: local members of the method in which it is defined
D: static member of outer class

5. Given public static void main(String args[])


{
Integer i; if(i==65)
{
System.out.println("65");
}
else
if(i==0)
{
System.out.println("0");
}
else
{
System.out.println(“garbage”);
}
}
A: output “0” B: NullPointerException C: Compilation error D: output “garbage”

6. Given public class Trial {static Double d;


public static void main(String args[])
{
if(d==0)
{
System.out.println("0");
}
4
USM’s Shriram Mantri Vidyanidhi Info Tech
else
Academy

5
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
{
System.out.println("garbage");
}
}
}
A: it will fail at runtime B: output 0
C: output garbage D: compiletime error

7. Which statement is wrong?


A: Externalizable is child of Serializable
B: String class is final hence cannot be serialized
C: When a class implements Serializable and it is deserialized using readObject(), constructor is never
invoked.
D: all the wrapper classes they implement Serializable

8. Finalize method is a method of the class


A: String B: Exception C: Object D: None of the above

9. Which of the following can be referenced by this variable?


A: The instance variables of a class only
B: The methods of a class only
C: The instance variables and methods of a class
D: The class variable

10. Which statement is true about a static nested class?


A: You must have a reference to an instance of the enclosing class in order to instantiate it.
B: It does not have access to non-static members of the enclosing class.
C: its variables and methods must be static.
D: must extend the enclosing class.

11. Which of the following methods cause the string object referenced by s to be changed?
A: s.concat() B: s.touppercase() C: s.repIace() D: None of the above

12. Given
{
public static void rnain(String [] args)
{
PassA p = new PassA(); p.start();
}

void start()
{
long [] a1 = {3,4,5}; long [] a2 = fix(a1);
System.out.print(a1 [0] + a1 [1] + a1 [2] + " ");
System.out.println(a2[0] + a2[1] + a2[2]);
}
long [] fix(long [] a3)
{
5
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
a3[1] = 7'; return a3;
}
}
A: 1 2 1 5 B: 1 5 1 5 C: 3 4 5 3 7 5 D: 3 7 5 3 7 5

13. What is the result of the following code? import java.util.*; enum
Animals
{
DOG("woof"), CAT("meow"), FISH("burbIe");
String sound;
Animals(String s) { sound = s; }
}
public class test11 { static Animals a; public static void main(String [] args) {
System.out.println(a.DOG.sound + " " + a.FISH.sound);
}
}
A: Multiple compilation errors
B: woof burble
C: Compilation fails due to an error on line 3

14. Inner class gets access to


A: outer class variables
B: outer class variables only if we created outer class object in inner class.
C: inner class variables only D: none of the above.

15. Which of the following is not a wrapper class?


A: String B: Integer C: Boolean D: Character

16. What is the output?


class A
{
int i,j;
A()
{
i=1;j=2;
}
}
public class Abc {
public static void main(String[] args) {
// TODO Auto-generated method stub
A obj1=new A();
A obj2=new A();
System.out.println(obj1.equals(obj2));
}
}
A. true B. false C. compiler error D. runtime error

5
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
17. Which of the following is not abstract?
A. Thread B. Collection C. AbstractList D. List

18. To provide access to members of the class to another class in different package which access specifier
is used?
A. Public B. protected C. private D. no modifier

19. Which of these methods is rounding function of Math class?


A. max() B. min() C. abs() D. all of the above

20. In java System.out is an object of type


A. InputStream B. PrintStream C. OutputStream D. BufferedInputStream

21. Which of the following statement is supported by an Anonymous inner class supports?
A. It can extend exactly one class and implement exactly one interface
B. It can extend exactly one class and can implement multiple interfaces
C. It can extend exactly one class or implement exactly one interface
D. It can implement multiple interfaces regardless of whether it also extends a class.

22. Which string instance method would return true when invoked liked this: a.method(b) where
a=”BUTTERfly” and b=”butterFLY”
a) equalsIgnoreCase() b) toUpperCase() c) toLowerCase() d) equals()

23. Which of the following is an ability of Reflection API in java?


A. Determining the state of an object B. Determining object validity
C. Determining duplicate classes D. Determination of the class of an object

24. What is the difference between this() and super() ?


A. super() constructor is invoked within a method of a class while this() constructor is used within the
constructor of the sub class.
B. this() constructor is invoked outside a method of a class while super() constructor is invoked within the
constructor of the sub class.
C. this() constructor is invoked within a method of a class while super() constructor is invoked outside the
constructor of the sub class.
D. this() constructor is invoked within a constructor of a class while super() constructor is used within
the constructor of the sub class.

25. What is the output of the following? public class MyClass


{
public static void main(String args[])
{
StringBuffer sb1=new StringBuffer("Anurag");
StringBuffer sb2=new StringBuffer("Anurag");
String ss1="Anurag";

System.out.println(sb1==sb2);
System.out.println(sb1.equals(sb2));
System.out.println(sb1.equals(ss1));
5
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
System.out.println("Poddar".substring(3));
}
}

A. False , true , true, dar B. False, true, false, ddar


C. Compiler error D. false,false, false , dar

26. Given following code, what will happen to the output? public class MyClass
{
public static void main(String args[])
{
String str1="hello";
String str2="hel";
String str3=str2+"lo";

if(str1==str3)
{

=="); System.out.println("str1 and str3 are


}
else
{

not =="); System.out.println("str1 and str3 are

}
if(str1.equals(str3))
{

equals"); System.out.println("str1 and str3 are


}
else
{
System.out.println("str1 and str3 are

not equals");
}
}
}

a) str1 and str3 are ==


str1 and str3 are equals

b) str1 and str3 are not ==


str1 and str3 are equals

5
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
c) str1 and str3 are ==
str1 and str3 are not equals

d) compilation error

27. Select a wrong statement about native method.


A. Native method can be static B. Native method can be abstract
C. Native method can be non-static D. Native method can be synchronized

28. Constructor is the class that does not provide information about, and access to, a single constructor of
a class.
A. True B. False

29. A class cannot be both abstract and final..


A. True B.False

30. String s1=”hello”; String s2=”hello”; which one will return true
A. s1==s2 B. s1.equals(s2) C. both a and b

32. What is the correct ordering for the import, class and package declaration when found in a single file?
A. package, import, class B. class, import, package
C. import, package, class D. package, class, import

33. When native method resolution fails we get


A. NativeResolutionFailedException B. NullPointerException
C. UnsatisfiedLinkError D. None of these

34. Select the correct statement about Functional Interface. A.


It should not contain default or static methods
B. It should contain only one abstract method.
C. It should contain more than one abstract methods.
D. None of these.

35. Which operation is allowed on String class


A. + B. - C. & D. &&

36. Using reflection u can


A. Access private fields B. Access private methods C. Both a and b D. None

37. JRE contains


A. Jvm B. jars C. dlls D. all of the above

38. Main() function is invoked by


A. Programmer B. class_loader C. jvm D. none of the above

39.. Address of next executing instruction is stored inside


A. method_area B. stack C. heap D. PC_Register

5
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy

40. Method area stores information about


A. Class_bytecode B. static_variables C. method_names D. all of the above

41. In java objects are created on


A. Stack B. heap C. both A & B D.none of the above

42. . Which of the following statements is true?


A. Main is public B. Main is static C. Main accepts String[] D. All of the above

43. According to the new version of java, along with byte,short,int ,char following type is also allowed
A. Double B. float C. String D. none of the above
44. By-default value for the Reference type is:
A. false B. 0 C. null D.none of these

45. In java by default member functions are


A. static B. virtual C. final D.all of the above

46. Just before object gets garbage collected following method is called
A. finalize() B. gc() C. main() D. none of the above

47. In java the rule is


A. member variable must be initialized before use B. local variable must be initialized before use
C. both a and b D. none of these

48. What will happen if static modifier is removed from the signature of the main method?
A. Compilation Error.
B. RunTime Error: NoSuchMethodError.
C. Program will compile and run without any output.
D. Program will compile and run to show the required output.

49. Under what conditions is an object's finalize() method invoked by the garbage collector? A.
When it detects that the object has become unreachable.
B. As soon as object is set as null.
C. At fixed intervalm it checks for null value.
D. None of the above.

50. Can constructor be inherited?


A. True B. False

51. Under what conditions is an object's finalize() method invoked by the garbage collector?
A. Just before object gets garbage collected. B. As soon as object is set as null.
C. At fixed intervalm it checks for null value. D. None of the above.

52. What is the output?


public class test10
{
5
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy

static void call(int x)


{ x+=2;
}
public static void main(String args[])
{
int num=0;
call(num++);
System.out.println(num);
}
}

A. 1 B. 2 C. 3 D. 0

53. Which of the following is the correct syntax for suggesting the JVM performs garbage collection.
A. System.free (); B. System.setGarbageCollection () ;
C. System.out.get () ; D. System.gc ();

54. Which of the following is not primitive data type?


A. int B. Boolean C.String D. float

55. Static member scope is


A. They are created when the class is loaded at runtime.
B. They are created when main get called.
C. They are created when class object get created.
D. They are created when class get modified.

56 What will be the result of attempting to compile and run the following code? public class test3
{
static int a; int b;
public test3()
{
int c; c=a; a++; b+=c;
}
public static void main(String args[])
{
new test3();
}
}

Select the one correct answer


A. The code will fail to compile since the constructor is trying to access static members
B. The code will fail to compile since the constructor is trying to use static field “a “ before it has been
initialized.
C. The code will fail to compile since the constructor is trying to use static field “b “ before it has been
initialized.

5
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
D. The code will fail to compile since the constructor is trying to use static field “c “ before
it has been initialized.
E. The code will compile and run without any problems.

57. What will happen if you compile/ run the following code?
public class Q 11
{
static String str1»= "main method with String[] args";
static String str2 = "main method with int[] args";
public static void main(String[] args) {
System.out.println(str1); .
}
public static void main(int[] args)
{
System.out.println(str2);
}}
A. Duplicate method main(), compilation error at line 6.
B. Duplicate method main(), compilation error at line 11.
C. Prints "main method with main String[] args".
D. Prints "main method with main int[] args".

58. What is the output of the following code?


class Test
{
Test(int 1')
{
System.outfprintln("Test(" +i +")");
}
}
public class Q12
{
static Test t1 = new Test(1);
Test t2 = new Test(2); static
Test t3 = new Test(3);
public static void main(String[] args)
{
Q12 Q = new Q12();
}
}
A. Test(1)
Test(2)
Test(3)
B. Test(3)
Test(2)
Test(1)
C. Test(2)
Test(1)
Test(3)

5
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
D. Test(1) Test(3)
Test(2)

59. What is the output of the following code?


String str = "Welcome"; si;r.concat(" to
Java!");
System.out.println(str);
A. Strings are immutable, compilation error at line 3.
B. Strings are immutable, runtime exception at line 3.
C. Prints "Welcome".
D. Prints “Welcome to Java!".

60. What is the output of the following code?


class MyClass ”
{
static int maxElements; MyClass(int
maxElements)
{
this.maxElements = maxElements;
}
}
public class Q19
{
public static void main(String[] args)
{
MyClass a = new MyClass(100); MyClass
b = new MyClass(100);
if(a.equals(—)
System.out.println("ObJects have tne same values ;, else
'
System.out.println("Objects have different values");
}
A. Compiles error at line 20 equals () method was not defined. B.
Compiles fine,runtime exception at line 20
C. Print “object have the same values”.
D. Print “object have the different values”;

61.What will happen if you compilel run the following code?


public class Q21
{
int maxElements;
void Q21()
{
maxElements = 100; ’
System.out. println(maxElements);
}
Q21 (int i)
{.

5
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
maxElements = i;
System.out.println(maxElements);
}
public static void main(String[] args)
{ Q21 a = new Q21();
Q21 b = new Q21(999);
}
}
A. Prints 100 and 999.
B. Prints 999 and 100.
C. Compilation error at line 3, variable maxElements was not initialized.
D. Compilation error while calling parameterized constructor

62. What will happen if you invoke the following method? public
void check()
{
System.out.println(Math.min(-0.0,+0.0));
System.out.println(Math.max(-0.0,+0.0));
System.out.println(Math.min(-0.0,+0.0) == Math.max(0.0,+0.0));
}
A. prints -0.0, +0.0 and false. B. prints -0.0, +0.0 and true.
C. prints 0.0, 0.0 and false D. prints 0.0, 0.0 and true
63. What will be the output of the followingicode?
1. String s1 = "Java2";
2. String s2 = "Java2";
3. if (s1 == s2)
4. System.out.println("We are twins");
5. else
6. System.out.println("We are not twins“);

A. We are twins
B. We are not twins
C. The program will not compile.
D. The program will compile, but will produce a run-time error.

64. In the following code, which is the earliest statement, where the object originally held in e, may be
garbage collected: public class Test { public static void main (String'a"Fg§[]){ Employee e =_new
Employee("Bob", 48); e.calculatePay();
System.out.println(e.printDetails()); _ e
= null;
e = new Employee("Denise", 36);

e.calculatePay();
System.out.println(e.printDetails());
}
}

6
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
A. Line 7 B. Line 8 C. Line 10 D. Line 11

65. non static variables are defined in


A. functions B. classes C. both 1 and2 D. none of the above.

66. String objects are


A. mutable B. immutable C. all the above D. None of the above

67. toString function is a non final method of


A. keyword B. method of String class
C. method of Object class D. None of the above

68. converting primitives to objects is called as


A. Conversion mechanisms B. Boxing C. Object Conversion D. none of the above

69. if we make constructors as static functions


A. compile time error B. runtime error C. coding error D. None of the above

70. non static variables are for


A. objects B. functions C. both 1 and 2 D. none of the above

71. class
A
{
int I;
public void m1()
{
System.out.println("value of i is" + i);
} }
public class Code1
{
public static void main(StringO args) {
A obj =new A(); A obj1 =new A(}; obj.I =3;
obj1. i=4;
System.out.prlntln{obj1.i +·" + obj.I);
}
this program will print

6
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
A. 3,4 B. 4,3 C. compilation error D. runtime error.

72.
class A
{
public void m1()
{
System.out.println("1");
}
public static void m2()
{
m1(); System.out.prinUn("2");
}
}
when we call m2 function,here output will be
A. 1, 2 B. 2, 1 C. runtime error D. compile time error

74. What is the output of following println statement


String str1 = “Hellow”;
System.out.println(str1.indexof(‘t’));
A. 0 B. can’t be predicted C. -1 D. 5

75.What could be output of the following fragment of code?


public class Test
{
Public static void main (String args[])
{
string x = “hellow”;
int y = 9;
System.out.println(x += y);
}
}
A. throws an exception as String and int are not compatible b)
hello9
c) Compilation error
d) None of these

76.What will be the output of the following fragment of code?


public class Test
{
public static void main(String [] args)
{
String s1 = “java”;
String s2 = “java”;
System.out.println(s1.equals(s2));
System.out.println(s1 == s2);
}

6
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
}
A. false true B. false false C. true false D. true true

77. Determine output


public class Test
{
public static void main(String args[])
{
String str = null;
if ( str.length() = = 0)
{
System.out.print(“1”);
} else if (str == null)
{ System.out.print(“2”);
} else {
System.out.print(“3”);
}
}
}
A. compilation fails B. “1” is printed C. “2” is printed
D. “3” is printed E. An exception is thrown at runtime

78.What could be output of the following fragment of code?


public class Test
{
Public static void main (String args[])
{
string x = “hellow”;
int y = 9;
System.out.println(x += y);
}
}
A. throws an exception as String and int are not compatible
B. hello9
C. Compilation error
D. None of these

79. class base


{
protected:
int a,b;
public:

void setab(int n, int m) (a=n; b=m;)


};
class derived zprotected vase

6
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
{ int c; public: void
setc(int n) {c=n;}
};
referring to the sample code above, how can you access the int member ”a” in class derived? A.
using member functions of base only.
B. only by using friend functions.
C. using member functions of derived only.
D. by using member functions of derived and base
E. by using any function.

80. Study the below program


Public class Singleton
{
Public static final Singleton instance = new Singleton();
Public Singleton()
{
}
Public static Singleton getInstance()
{
return instance ;
}
Public void foo()
{
}
}
Public class Test
{
Public static void main(String[] args)
{
Singleton a = new Singleton();
a.foo();
Singleton b = Singleton.getInstance();
b.foo();
}
}
Which of the numbered lines is a problem ?
A. 1 B. 3 C. Both D. None

81. If an instance of class A is created in what in what order will the numbered lines be hit public
class A
{
1: public int a = 1;
Public A()
{
2: a = 2;
}
{
3: a =3;

6
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
}
}
A. Class will not compile B. 1 3 2 C. 2 1 3 D. 2 1

82. How many times will be the line numbered as 1 be hit ?


Public class A
{
Public static int a =1;
Public A()
{
a = 2;
}
Static
{
a = 3;
}
}
Public class Test
{
Public static void main(String[] args)
{
A a1 = null;
A a2 = new A();
}
}
A. Program will not compile B. 1 C. Never D. 4

83. What is the super class of integer ?


A. Object B. Numeric C. Number D. Short

84. What is the name of the concept by which I can assign an int directly to an Integer ?
A. Casting
B. Auto Assignment C.
Auto boxing
D. It is not possible. Primitive type cannot be assigned to objects

85. Compiler which converts bytecode to native code is


A. Jit_compiler B. javac_compiler C. byte_compiler D. none of the above

86.Data types in java are


A. Primitive_type B. reference_type C. both a and b D. none of hese

87. What is the correct order?


A. Linking_loading_initializing B. loading_linking_initializiing C.
initializing_loading_linking D.loading_initializing_linking

88. Java does not support


A. pointers B. friend_keyword
6
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
C. multiple_inheritance D. all of the above

SOCKET PROGRAMMING
1. Which of the following class allows Tcp Server to wait for client on a particular port?
A: InetAddress B: ServerSocket C: Socket D: none of the above

2. One of the following port range is valid for Network programming in java
A: 1 to 65535 B: 1023 to 65535 C: 1024 to 65535 D: 0 to 1023

3. Which one is used to send packet over the network in case of UDP?
A: DatagramPacket B: Socket C: DatagramServer D: DatagramSocket

4. Which of the following is Application level protocol?


A: FTP B: HTTP C: JRMP D: all of the above

5. A is an endpoint for communication between two machines.


A. ServerSocket B. Socket C. DatagramSocket D. DatagramPacket

6. Which of the following class allows UDP Server to wait for client on a particular port?
A: InetAddress B: DatagramSocket
C: DatagramPacket D: none of the above

7. One of the following class is used to represent IP address of a machine.


A: IPAddress B: InetAddress C: InternetAddress D: InternetPacketAddress

8. Which method is used to wait for client to get connected in TCP? A: accept
B: receive
C: wait
D: socketWait

9. Which of the following is Application level protocol?


A: TCP B: HTTP C: UDP D: all of the above

10. The class which is used to send the packet in case of UDP is
A. Socket B. UDPSocket C. UserDatagramPacket D. UserDatagramSocket

11. The class which represents IP address of machine is


A. InternetAddress
B. IPAddress
C. InetAddress
D. none of the above

12. Which is Application layer


A. HTTP
B. FTP
C. SMTP
6
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
D. all of the above

13. method is used to wait for client request in UDP


A. Wait
B. receive
C. accept
D. none of these

14. method is used to wait for client request in TCP


A. Wait
B. receive
C. accept
D. none of these

15. If we want to pass an object over network it should implement


A. Runnable
B. Serializable
C. Cloneable
D. none of these

16. class is used to make server wait for client request in TCP.
A. Socket
B. ServerSocket
C. SocketInputStream
D. none of these

17. Valid range of port number for a java application is


A. 0 to 65535
B. 1 to 65535
C. 1024 to 65535
D. none of these

18. Marshalling is
A. Converting packets into data
B. converting data into packets
C. converting bytes into character

19. TCP is reliable


A. True B. false

20. What will be printed out if you attempt to compile and run the following code?
int i=9; switch
(i) { deiault:
System.out.println("default"); cazse
0:
Sy:stem.out.println("zero");
break; case 1:
6
USM’s Shriram Mantri Vidyanidhi Info Tech
Academy
System.out.println("one"); case
2: system.out.println("two"); }
a) default
b) default, zero
c) error default clause not defined
d) no output displayed

21. Which of the following lines will compile without warning or error.
a) float f=1.3;
b) char c="a";
c) byte b=257; ‘
d) boolean b=null;
e) int i=10;

22. How to terminate JVM when I close all the application windows?
a. Systemexit(u) b. System.exit( 1) c. 3ystem.exit(2) d. All are invalid answers

You might also like