You are on page 1of 18

Java Basics

1) _____ is a group of similar classes and interfaces.


(a) Project
(b) Package
(c) Wrapper Classes
(d) Applet

2) _______ is the default package in java.


(a) java.util
(b) java.lang
(c) java.io
(d) java.awt

3) java.io and java.util are the example of _________


(a) project
(b) package
(c) Wrapper class
(d) Applet

4) When you compile a java program, the compiler converts a human readable source file into platform
independent code that a JVM can understand. What is this platform independent cod called?
(a) API
(b) Bytecode
(c) Class
(d) Package

5) What is JVM?
(a) All java files are compiled into class files that contain JVM.
(b) It is an abstract machine that hides underlying operating system from java applications and executes
the java bytecode.
(c) It is libraries of compiled code that can be used in java programs.
(d) It is a java program that contains many classes.

6) What is java API?


(a) It is also known as initial class that contains main method.
(b) It is independent of computer system it has to run upon.
(c) It is libraries of compiled code that can be used in java programs.
(d) All java applications begin their executions from API.

7) Choose the incorrect characteristics of a Java Language program.


(a) Write Once Run Anywhere
(b) Platform Independent
(c) Object Oriented Programming
(d) Licensed Product

8) Reducing a problem or task into relevant and necessary details is an example of the ________ principle.
(a) Interface
(b) Abstraction
(c) Encapsulation
(d) Modularity

9) Designing a class so that it shields certain parts of an object from other objects is an example of the
____________ principle.
(a) Interface
(b) Abstraction
(c) Encapsulation
(d) Modularity
10) The _______ of an application is visible to user and all other functionality remains hidden.
(a) Interface
(b) Abstraction
(c) Encapsulation
(d) Inheritance

11) __________ members are not accessible outside the class.


(a) private
(b) protected
(c) public
(d) default

12) __________ members are accessible from classes in the same package only.
(a) private
(b) protected
(c) public
(d) default

13) __________ members are accessible in the same package and sub class.
(a) private
(b) protected
(c) public
(d) default

14) __________ members are accessible anywhere the class is accessible.


(a) private
(b) protected
(c) public
(d) default

15) Relationship between Abstraction and Encapsulation is:


(a) Abstraction is the way to implement Encapsulation.
(b) Encapsulation can be applied between the Abstractions.
(c) Encapsulation is the way to implement Abstraction.
(d) None of these

16) The first line of Function declaration is known as :


(a) Function signature
(b) Function Prototype
(c) Function calling
(d) None of the above

17) The access specifiers are:


(a) void, int, boolean, char
(b) Arrays, Strings, objects
(c) public, private, protected
(d) All of the above

18) Prototype for the returnable function xyz( ) which returns a boolean value and accepts an integer and
character through its parameter list, is:
(a) void xyz( )
(b) int xyz(char t, int b, int y)
(c) void xyz(int a, char b)
(d) boolean xyz(int a, char b)
19) A function which does not change the state of its object :
(a) Pure function
(b) Impure function
(c) Calling function
(d) Called function

20) The actual parameter is written in the :


(a) function prototype
(b) function calling statement
(c) function signature
(d) None of the above

21) Function signature is part of :


(a) Function body
(b) Function calling statement
(c) Function prototype
(d) Function heading

22) A returnable function can have:


(a) Only one return statement
(b) Several return statements and any number of them can be executed.
(c) Several return statements but only one is executed
(d) None of the above

23) During call by value:


(a) The formal parameter is copied to the actual parameter
(b) The actual parameter is copied to the formal parameter.
(c) Both option a or option b, depending on the question.
(d) None of the above

24) During function call, the actual parameter gets copied to the formal parameter(in call by value). This is known
as:
(a) static binding
(b) dynamic binding
(c) Holistic binding
(d) All of the above

25) What will be the output of the given code segment:

(a) 0123456789
(b) 012
34
56
78
9
(c) 01
23
45
67
89
(d) None of these
26) Polymorphism is implemented in software using:
(a) Dynamic binding
(b) Function calling
(c) Function overloading
(d) None of the above

27) The following function is a part of some class which computes and returns the greatest common divisor of
any two numbers.
There are some places in the code marked by ?1?, ?2?, ?3?, ?4? and ?5? which must be replaced by
statement/expression so that the function works correctly.

(a) (1) a > 0 (2) b % a (3) a (4) r (5) b


(b) (1) b > 0 (2) a % b (3) b (4) r (5) a
(c) (1) a > 0 (2) a % b (3) a (4) r (5) a
(d) (1) b > 0 (2) b % a (3) b (4) r (5) b

28) State the final value of q at the end of the code segment:

(a) 28
(b) 27
(c) 30
(d) 29

29) The following function is a part of some class which checks if a positive integer is an Armstrong number by
returning true or false.
( A number is said to be Armstrong if the sum of cubes of all its digits is equal to the original number) the
function does not use modulus operator(%) to extract digit.
There are some places in the code marked by ?1?, ?2?, ?3?, ?4? and ?5? which must be replaced by
statement/expression so that the function works correctly. The statements / expressions at these places will
be:
(a) (1) 0 (2) 0 (3) digit (4) num/10 (5) num==sum
(b) (1) 0 (2) s+f (3) digit*digit*digit (4) f/10 (5) digit==sum
(c) (1) 0 (2) f (3) digit*digit*digit (4) num/10 (5) num==sum
(d) (1) 0 (2) f*10 (3) digit*digit*digit (4) f (5) N==sum

30) State the output of the given code segment:

(a) b is 5
(b) No output
(c) a is 10
(d) None of these

31) Give the output of the following code:

(a) Infinite Loop


(b) m is 0
(c) m is 10
(d) m is 1

32) What will be the expression or statement marked


as ?1?, ?2?, ?3?, ?4? and ?5? in the following code?
?1? a>0 ?1?
?2? b%a
?3? a
?4? r
?5? b

33) Name the access specifier with maximum scope


(a) public
(b) private
(c) protected
(d) default

34) A COMPOUND STATEMENT IN A JAVA PROGRAMMING IS ENCLOSED UNDER


(a) PARENTHESIS
(b) CURLY BRACKETS
(c) SQUARE BRACKETS
(d) NONE

35) A JAVA PROGRAM EXECUTES BUT DOES NOT GIVE THE DESIRED OUTPUT .IT IS DUE TO THE
(a) LOGICAL ERROR
(b) SYNTATICAL ERROR
(c) GRAMMATICAL ERROR
(d) NONE

36) Write the output of following program segments:


System.out.print(‘A’ + 32); 
 System.out.println(“A” + 32); 
(a) 2A32
(b) A32”A”32
(c) 97A32
(d) 6532A32

37) What will be stored in variable grade if mark = 85?


String   grade = (marks >= 90) ? “A”:  (marks >= 80) ? “B” : “C”;
(a) A
(b) B
(c) C
(d) A, B
38) What will the output of the following program snippet  if n = 5?
for ( int i = 1; i <= n; i++)
{
  k = (i * i * i) - 1;
System.out.print(k + “   ”); 
}

(a) 2  9  28  65
(b) 1  8  27  64  125
(c) 0  7  26  63  124
(d) 0  7  26  63

39) Access specifier that allows member variables of a class to be used by all the classes in the same package as
well as all the subclasses outside the package.
(a) public
(b) private
(c) protected
(d) friendly

40) Method name is an example of: 


(a) identifier
(b) keyword
(c) data type
(d) literal

41) Fill in the blank numbered from (A) to(D) 4 in the following program that attempts to find 5 n : 
class Power 
{  
int getresult ( __(A)__) 
{
int pro =   __(B)__ ;
for(int i = 1; I <= n; i++) 
pro = pro * __(C)__ ; 
__(D)__ ; 

void callerFunct ( ) 
{
int p;
 p = getresult(5); //calling function getresult ( ) 
System.out.print (p);
 }
 }

(a) int n, 1 , i, return pro


(b) int i, 1, 5, return pro
(c) int n, 1 , 5, return pro
(d) int n, 0 , i, System.out.println(pro);

42) Parameters that appears in the function prototype are 


(a) actual parameters
(b) formal parameters
(c) instance variables
(d) none of the above

43) Which of the following is incorrect regarding final keyword used in Java?
(a) the variable declared as final become constant
(b) the member function declared as final can be overridden
(c) the class declared as final can not be inherited
Correct answer : b

44) Which out of the given class is related to binary file?


(a) FileWriter
(b) FileWriter
(c) FileOuputStream
(d) PrintWriter
Correct answer : c

45) What will the function hard( ) print if the value of k = 8.

(a) 10
(b) 15
(c) 3
(d) 30
Correct answer : a

46) What is a constructor?


(a) A member method with
programmer defined name.
(b) A static method
(c) A member method with same
name as of its class
(d) Main method is also known as constructor

47) What are the two types of constructors?


(a) Pure and impure.
(b) Procedural and Manipulative.
(c) Parameterised and Non-Parameterised
(d) Static and Non-Static

48) Which one is a temporary instance out of the following?


(a) new Student()
(b) Student ob = new Student()
(c) BufferedReader ob = new BufferedReader()
(d) Student ob = new Student(12, ”abc”)

49) Which java classes are required to write and read binary files?
(a) StringTokenizer class
(b) FileReader, FileWriter
(c) FileOutputStream, FileInputStream
(d) Math class

50) What is a Buffer?


(a) Temporary storage to store a group of files
(b) Temporary storage used to hold data until enough has been collected that it is worth transferring
(c) Group of functions
(d) Group of tokens

51) What is a Buffer?


(a) Group of files
(b) A memory area where data is temporarily stored before it is written to the file.
(c) Group of functions
(d) Group of tokens

52) Which function closes the stream and releases the resources that were busy in the stream?
(a) finish()
(b) close()
(c) stop()
(d) end()

53) Which statement opens a text file in append mode?


(a) FileReader objname = new FileReader(filename);
(b) FileReader objname = new FileReader(filename, true);
(c) FileWriter objname = new FileWriter(filename);
(d) FileWriter objname = new FileWriter(filename,true);

54) Which package contains file handling classes?


(a) java.util
(b) java.io
(c) java.lang
(d) java.net

55) What is the purpose of package and import keywords?


(a) Access class(es) from a package
(b) Create a package and access class(es) from a package respectively
(c) Create a class and access that class
(d) Access class(es) from a package and create a package respectively

56) this keyword refers to which entity?


(a) Object received as formal parameter
(b) Local variable
(c) Currently invoked object
(d) Object passed as actual parameter

57) What is instantiation?


(a) Process of creating a class
(b) Process of creating a function
(c) Process of creating object
(d) Process of creating a package

58) What is the relation between a class & object?


(a) A Class is an object factory.
(b) Object is a class factory.
(c) An object is a group of classes.
(d) A class cannot exist without an object.

59) How the features and behaviour of a real-world object are depicted in software terms?
(a) Features by variables and Behaviour by methods.
(b) Features by methods and Behaviour by variables.
(c) By packages.
(d) By polymorphism.

60) The two-step process of converting source code to machine code involves?
(a) Step 1: Java Compiler Step 2: Java Virtual Machine.
(b) Step 1: Java Virtual Machine. Step 2: Java Compiler
(c) Step 1: Class Step 2: Objects.
(d) Step 1: Abstraction Step 2: Encapsulation

61) What is an exception?


(a) Compile Time Error
(b) Run-Time Error due to unexpected condition
(c) Logical Error
(d) Syntax and Semantics error

62) A try block can be followed by how many catch blocks?


(a) 0
(b) multiple
(c) 1
(d) 2

63) Which block executes no matter whether an exception takes place or not?
(a) try
(b) catch
(c) finally
(d) all of the above

64) An object of which class is created when a number is divided by zero?


(a) DivideByZero
(b) NumberFormatException
(c) ArithmeticException
(d) NullPointerException

65) Due to which code WORA feature of JAVA is exercised?


(a) Source Code
(b) Machine Code
(c) Byte code
(d) NullPointerException

66) Primitives and Reference data types allow us to store which values respectively?
(a) int and char
(b) char and int
(c) Rvalue and lvalue
(d) lvalue and rvalue

67) Select the primitive data type from the following?


(a) Character
(b) char
(c) Integer
(d) String

68) What is the definition of Coercion?


(a) Automatic conversion of smaller datatype to bigger datatype by java compiler.
(b) Automatic conversion of bigger datatype to smaller datatype by java compiler.
(c) Explicit conversion of smaller datatype to bigger datatype by programmer
(d) Explicit conversion of bigger datatype to smaller datatype by programmer

69) Select the correct output of the statement System.out.println((int)’A’ + 1 + ’1’ + ’A’)?
(a) 132
(b) 180
(c) 130
(d) String

70) Wrapper classes belong to which package?


(a) java.util
(b) java.lang
(c) java.io
(d) java.net

71) Which statement of the following is not true for a class?


(a) Class is a blue print of objects
(b) All Classes are readymade
(c) A class can contain static and nonstatic members.
(d) A class can contain multiple methods.

72) Which operator is required for explicit type conversion?


(a) (type)
(b) Dot
(c) Assignment
(d) Increment/Decrement

73) String x = “123.45”. Which of the following statements will not produce any error?
(a) double y=Double.parseDouble(x);
(b) Double y=Double.parseDouble(x);
(c) double y=double.parseDouble(x);
(d) double y=double.parsedouble(x);

74) What will be the value of x and y after execution of following statements:
x = 10, y = 2; y *= ++x – x + y++;
(a) x = 11, y = 4
(b) x = 4, y = 11
(c) x = 10, y = 3
(d) x = 11, y = 3

75) Which statement of the following will declare a constant alpha and assign the last lowercase vowel in
alpha?
(a) char alpha=’u’;
(b) this char alpha=’u’;
(c) final char alpha=’u’;
(d) const char alpha=’u’;

76) Arrange the following operators according to their order of execution?


A) > B) ++ C) && D) = E) % F) ? :
(a) A, B, C, D, F
(b) B, A, C, D, F, E
(c) B, E, A, C, F, D
(d) F, E, D, C, B, A

77) If the values of a and b are 5 and -5 then what will be the output of the following statement:
System.out.println( !(a == b && b != Math.abs(a))),?
(a) 10
(b) 0
(c) true
(d) false
78) If the values of x and y are true and false respectively then what will be the output of the following
statement?
System.out.println(x = = y ? false : true);?
(a) 0
(b) 1
(c) true
(d) false

79) What will be the output of the statement System.out.println(”hello\\friends\”” );


(a) hello\friends
(b) hello\\friends
(c) hello\friends”
(d) error

80) What is a variable in Java?


(a) Named memory location
(b) A function
(c) A package
(d) An object

81) Which expression of the following is a mixed expression?


(a) 2+3.5+4
(b) 2+3-3
(c) 2/3%4
(d) All are mixed expressions

82) Which of the following statements will print true as output if the value of a is 9?
(a) System.out.println(a = 9);
(b) System.out.println(a = = 9);
(c) System.out.println(a * 1);
(d) System.out.println(a % 9);

83) How many bytes will be required if one variable of each datatype (byte, short, char, double) are used?
(a) 13 Bytes
(b) 12 Bytes
(c) 16 Bytes
(d) 1 + 4 + 2 + 8 Bytes

84) Which statement of the following is not a jump statement?


(a) System.stop()
(b) System.exit()
(c) return
(d) break

85) What will be the output of following code snippet:


int a = 10, b = 5, i = 1;
switch(i)
{
case 1: a = a + 10;
case 2:b = b - 1; break;
case 3:a = a + b; b = b + 3; break;
default: a = a + 2;
}
System.out.println(a + ”,” + b);

(a) 20,4
(b) 10,5
(c) 20,5
(d) 24,7

86) What will be the output of following code snippet:


for(N = 543; N > 0;)
{
System.out.print(N / 10);
}

(a) 545454………infinite times


(b) 345
(c) 543
(d) 543……infinite times

87) What will be the output of following code snippet:


char ch;
for (int x = 97; x <= 100; x++)
{
ch = (char)x;
System.out.print(ch + ”,”);
if(ch == ’a’)
break;
}

(a) a
(b) a up to infinite times
(c) abcd
(d) 979899100

88) The code given below can be rewritten with:

if(per >= 90.0 && maths >= 95.0 && computer == 100)
System.out.println(“Admission granted”);
else
System.out.println(“Admission not granted”);

(a) Nested if
(b) if else if ladder
(c) switch statement
(d) Iterative statements

89) What is the error in the given code?


class WORK
{
public static void main()
{
String alphabet = “A”;
switch(alphabet)
{
case “A”:
case “E”:
case “I”:
case “O”:
case “U”:
System.out.println("CAPITAL VOWEL");
}
}
}
(a) switch cannot test a String literal
(b) break is missing after the cases
(c) default is missing
(d) Letter S of switch must be in capital

90) Write the output of the following code if the value of channel is 301?
switch (channel)
{
case 301: System.out.println(“Star news”);
case 302: System.out.println(“BBC news”);
case 303:
System.out.println(“News Channel”);
break;
case 105:
case 107:
case 102:
System.out.println(“Entertainment Channel”);
break;
}
(a) Star news
BBC news
News Channel
(b) News Channel
(c) News Channel
Entertainment Channel
(d) Error

91) In the code given below, which variable(s) can be used by the own class and only subclasses of Superclass

class Superclass
{
public int a;
private int b;
protected int c;
char d;
}
(a) a
(b) b
(c) c
(d) d
92) What will be the output of the above code?
class Jagat
{
public static void main(String args[])
{
int a = 10;
{
int b = 5;
}
System.out.println(b);
}
}

(a) 5
(b) 15
(c) Error
(d) 0

93) What will be the output of the following code snippet?


for (i = 1; i <= 1; i++)
{
for (j = 1;j <= 2;j = j + 3)
{
if (i % 2 == 0)
continue;
else
System.out.println(i);
}
System.out.println();
}

(a) 1
(b) 1
2
(c) 1
3
(d) 1
2
3

94) Method void digitFrequency() has been coded to find frequency of each digit present in the number and
display it. Based on it answer the questions (A) to (E).
void digitFrequency()
{ for(int i = 0; i <= 9; i++)
{ int c = ?1?;
int ?2? = i;
while(n != 0)
{ d = ?3?;
if(?4?)
c++;
}
?5?(c > 0)
System.out.println(I + ”\t” + i);
}
}

(A) Select the correct option for ?1?:


(a) 0
(b) 1
(c) 2
(d) n

(B) Select the correct option for ?2?:


(a) n
(b) 0
(c) 1
(d) 2

(C) Select the correct option for ?3?:


(a) n
(b) 0
(c) n%10
(d) 2

(D) Select the correct option for ?4?:


(a) d==n
(b) d==0
(c) d==i
(d) d==2

(E) Select the correct option for ?3?:


(a) if
(b) if else
(c) for
(d) switch

95) Which statement stands true with regard to invoking a method by passing a value of primitive data type:
(a) Changes made in formal parameters are not reflected in actual parameters
(b) Changes made in formal parameters are reflected in actual parameters
(c) Changes made in actual parameters are not reflected in formal parameters
(d) Changes made in actual parameters are reflected in actual parameters

96) We do not need to create an object to access a class(static) method. Which one of the following is the perfect
example endorsing the above statement?
(a) Math.sqrt()
(b) Scanner sc=new Scanner(System.in);
(c) Student ob=new Student();
(d) StringTokenizerst=new StringTokenizer(“hello friends”,” “);

97) The keyword which resolves the conflict when names of global and local variables are same?
(a) new
(b) final
(c) this
(d) class

98) What is function signature?


(a) The number and datatype of arguments received
(b) The number and datatype of local variables declared
(c) The global variables
(d) Global variables and Local variables

99) With respect to the following code, answer questions (A) and (B)

booleanArmstrongNum( int N )
{
int sum = ?1?
int Num = N;
while(num > 0)
{
int f = num / 10;
int digit = num % 10;
sum = ?2?;
num = num / 10;
}
if(sum = N)
return true;
else
return false;
}

(A) What is ?1?


(a) 0
(b) 1
(c) Num
(d) N

(B) What is ?2?


(a) digit
(b) sum+digit
(c) sum
(d) N

100)The following is a function of some class which checks if a positive integer is an Armstrong number by
returning true or false, A number is said to be an Armstrong if the sum of the cube of all its digit is equal to
the original number the function does not use the modulus (%) operator to extract digits. Answer the
questions (A) to (E)

(A) What is the expression at ?1?.


(a) 0
(b) 1
(c) N
(d) N*1

(B) What is the expression at ?2?.


(a) f
(b) f/10
(c) s
(d) f*10

(C) What is the expression at ?3?.


(a) d*d
(b) digit*digit*digit
(c) digit*3
(d) digit*f

(D) What is the expression at ?4?.


(a) num*10
(b) num/f
(c) num/10
(d) num/sum

(E) What is the expression at ?5?.


(a) num= =s
(b) num= =sum
(c) N= = f
(d) N= = sum

You might also like