You are on page 1of 17

Java Programming

Answers are underlined

1. is the process by which objects of one class acquire the properties of objects of another
class.
a) Data Abstraction
b) Encapsulation
c) Inheritance
d) Polymorphism

2. An operation may exhibit different behaviour in different instances. This is an example of


a) Data Abstraction
b) Polymorphism
c) Encapsulation
d) Inheritance

3. refers to the linking of a procedure call to the code to be executed in response to the call.
a) Dynamic Binding
b) Message Communication
c) Polymorphism
d) Objects

4. . Java communicates with a webpage through a special tag called


a) <javac>
b) <javap>
c) <applet>
d) <java>

5. Identify the incorrect rule of an identifier.


a) They must not begin with a digit.
b) The length of identifier is restricted to 16.
c) Uppercase and lowercase letters are different.
d) . They can have alphabets, digits and underscore.

6. . are symbols used to indicate where groups of code are divided and arranged.
a) Seperators
b) Operators
c) Literals
d) Identifiers

7. . statements pass control to the beginning or end of the current block.


a) Iteration statement
b) Synchronization statement
c) Jump statement
d) Guarding statement

8. The static variables are also called as


a) class variable
b) member
c) message
d) . class

9. In java characters are compared based on their values.


a) Bytecode
b) Unicode
c) Ascii code
d) Assembly code

10. Which of the following is a correct signature for the main method?
a) static void main(String[] args[])
b) public static void main(String args)
c) public void main(String[] args)
d) public static void main(Strings[] args)

11. Keyword indicates that method do not return any value.


a) null
b) void
c) static
d) Final

12. The is an entry-controlled loop.


a) While
b) do-while
c) Switch
d) if

13. A literal character is represented inside a pair of


a) Single quotes
b) double quotes
c) brackets
d) parenthesis

14. The backslash character constant “\t” represents


a) form feed
b) newline
c) horizontal tab
d) backslash

15. Identify the invalid constant declaration:


a) final int strength = 100;
b) final intpass_mark =
50; c) final int max value
= 50
d) final float P1 = 3.14159;

16. Identify the output of the following code:


System.out.print(“Hello”)
System.out.print(“Java”)

a) Hello Java
b) Hello
c) HelloJava
d) “Hello” “Java”

17. Using arithmetic operators, the output of 15/10 is


a) 1.5
b) 1
c) 1.0
d) error

18. Fill the missing expression to add the value 5 to the variable x.
int x = 10;
x 5;

a) +=
b) =
c) =+
d) +

19. Fill in the missing part to create a greeting variable assign it the value Welcome.
String greeting =

a) ‘Welcome’
b) “Welcome”
c) Welcome
d) {“Welcome”}

20. Find the output of the following


code: String firstName = "Hello ";
String lastName = "John";
System.out.println(firstName +lastName);

a) Hello + John
b) Hello+John
c) Hello
d) Hello John

21. What is the output of the following code?


. public class Main {
public static void main(String[] args) {
String txt = "Find me";
System.out.println(txt.indexOf("m"));
}
}

a) 2
b) 3
c) 5
d) 6
22. Find the output of the following code:

public class Main {


public static void main(String[] args) {
String[] fruits = {"Apple", "Mango", "Orange", "Grapes"};
fruits[1] = "Pineapple";
System.out.println(fruits[1]);
}
}

a) Apple
b) Mango
c) Pineapple
d) Error

23. Find the output of the following code:


public class Main {
public static void main(String[] args) {
int[][] myNumbers = { {1, 2, 3, 4}, {5, 6, 7} };
int x = myNumbers[1][2];
System.out.println(x);
}
}

a) 1
b) 2
c) 5
d) 7
24. Find the output of the following
code: public class Main {
public static void main(String[] args) {
int i = 0;
while (i <= 5) {
System.out.print(i+" ");
i++;
}
}
}

a) 0 1 2 3 4 5
b) 0 1 2 3 4
c) 1 2 3 4 5
d) Error

25. . Find the output of the following code:


public class Main {
public static void main(String[] args) {
System.out.println(Math.abs(-9.7));
}
}

a) -9.7
b) 9,7
c) . 9
d) error

26. Output of the progrm


classMain {
publicstaticvoidmain(String args[]) {
intx = 0;
inty = 10;
intz = y/x;
}
}

a) Compiler error
b) Compiles and Run file
c) Compiles fine but throws arithmetic exception
d) None

27. classBase extendsException {}


classDerived extendsBase {}

publicclassMain {
publicstaticvoidmain(String args[]) {
// some other stuff
try{
// Some monitored code
thrownewDerived();
}
catch(Base b) {
System.out.println("Caught base class exception");
}
catch(Derived d) {
System.out.println("Caught derived class exception");
}
}}
a) Caught base class exception
b) Caught derived class exception
c) Compile error
d) Compile error because base class exception is caught before derived class

28. classTest
{
publicstaticvoidmain (String[] args)
{
try
{
inta = 0;
System.out.println ("a = "+ a);
intb = 20/ a;
System.out.println ("b = "+ b);
}
catch(ArithmeticException e)
{
System.out.println ("Divide by zero error");
}
finally
{
System.out.println ("inside the finally block");
}
}
}
a) Compile error
b) Divide by zero
error c) a=0
Divide by Zero error
Inside the finally block
d) a=0

29. Which of these is a super class of all errors and exceptions in the Java language?
a) Runtime Exception
b) Throwable
c) Catchable
d) None

30. The built-in base class in Java, which is used to handle all exceptions is
a) Raise
b) Exception
c) Error
d) Throwable

31. Output of following Java


program? classMain {
publicstaticvoidmain(String args[]) {
System.out.println(fun());
}

intfun()
{
return20;
}
}
a) 20
b) Compile error
c) Garbage Collection
d) 0

32. Predict the output?


classMain {
publicstaticvoidmain(String args[]) {
System.out.println(fun());
}
staticintfun(intx = 0)
{
returnx;
}
}

a) 0
b) Garbage value
c) Compile error
d) Runtime error

33. What is the extension of compiled java classes?


a) .txt
b) js
c) .class
d) .java

34. Which exception is thrown when java is out of memory?


a) MemoryError
b) OutOfMemoryError
c) MemoryOutOfBoundsException
d) MemoryFullException

35. Which of these keywords is used to define interfaces in Java?


a) intf
b) Intf
c) interface
d) Interface

36. Which of these statements is incorrect about Thread?


a) start() method is used to begin execution of the thread
b) run() method is used to begin execution of a thread before start() method in special cases
c) A thread can be formed by implementing Runnable interface only
d) A thread can be formed by a class that extends Thread class

37. Which of these keywords are used for the block to be examined for exceptions?
a) check
b) throw
c) catch
d) try

38. When does Exceptions in Java arises in code sequence?


a) Run Time
b) Compilation Time
c) Can Occur Any Time
d) None of the mentioned

39. Which of these keywords must be used to monitor for


exceptions? a) try
b) finally
c) throw
d) catch

40. Which of these keywords is used to manually throw an exception?


a) try
b) finally
c) throw
d) catch

41. Which of these packages contain all the Java’s built in exceptions?
a) java.io
b) java.util
c) java.lang
d) java.net

42. Which of these class is used to create user defined exception?


a) java.lang
b) Exception
c) RunTime
d) System

43. Which of these class is superclass of String and StringBuffer class?


a) java.util
b) java.lang
c) ArrayList
d) None of the mentioned

44. Which of these operators can be used to concatenate two or more String objects?
a) +
b) +=
c) &
d) ||

45. Which of these method of class String is used to extract a single character from a String object?
a) CHARAT()
b) chatat()
c) charAt()
d) ChatAt()

46. Which of these constructors is used to create an empty String


object? a) String()
b) String(void)
c) String(0)
d) None of the mentioned

47. Which component is used to compile, debug and execute the java programs?
a) JRE
b) JIT
c) JDK
d) JVM

48. Which one of the following is not a Java feature?


a) Object-oriented
b) Use of pointers
c) Portable
d) Dynamic and Extensible

49. Which of these cannot be used for a variable name in Java?


a) identifier & keyword
b) identifier
c) none of the mentioned
d) keyword

50. What is the extension of java code files?


a) .js
b) .txt
c) .class
d) .java

Key

1. (c)
2. (c)
3. (a)
4. (c)
5. (b)
6. (a)
7. (c)
8. (a)
9. (b)
10. (d)
11. (b)
12. (a)
13. (d)
14. (c)
15. (c)
16. (c)
17. (b)
18. (a)
19. (c)
20. (d)
21. (d)
22. (c)
23. (d)
24. (a)
25. (a)
26. (c)
27. (d)
28. (c)
29. (b)
30. (d)
31. (b)
32. (c)
33. (c)
34. (c)
35. (c)
36. (b)
37. (d)
38. (a)
39. (a)
40. (c)
41. (c)
42. (b)
43. (b)
44. (a)
45. (c)
46. (a)
47. (c)
48. (b)
49. (d)
50. (d)

You might also like