You are on page 1of 32

TCS PROCTORED EXAM

JAVA

PREVIOUS EXAM’S MCQS

100% COMMON
1.class A

Final a;

System.out.println(a);

….

Ans : error in line 3


2.To find length of the string:
String a;
1.a.length
2.a.length()

Ans : a.lenght();
3.class Box{

…..

Class solution {

Box box[]={b1,b2,b3,b4,b5};

For(int i=0;i<box.length();i++)

Ans : error ( because we should use box.length)


4.Object includes ?
1. attributes
2.behaviour
3.both
4.None
Ans : 3
5.____is also known as static variable.. ?
1) class variable
2) instance variable
3) local variable
4) all of above
Ans :1
6.Predict output of program
char ch=127;
ch++;
System . out . println(ch+" = "+(int)ch);
1) compilation error
2) ? = 128
3) garbage value =- 128
4) none of above
Ans :3
7.Predict output of program
String s[] = {hybernate, java, object}
Arrays . sort(s);
for(String k in s)
{
System . out . println(k);
}

1) java hybernate object


2) hybernate java object
3) hybernate object java
4) object java hybernate
Ans:2
8.Predict output of program
String str = "I like JAVA";
System . out . println(str . length());
1) 12
2) 11
3) 10
4) 9
Ans : 2
9.Which operator gives result if no condition
satisfies.?
1) IN
2) OR
3) NOT
4) AND
Ans :3
10.Which is not the correct declaration ?
1.int a_1
2.int 1_a
3.int A1
4.None
​Ans: 2
11.Tick the correct one-
1.Java is platform independent
2.Jvm is platform dependent
3.Jvm converts byte code into machine
level code
Ans: tick all of these
12.Static int a=1;
Inc()
{
a++;
Print(a)
}
Inc()
Inc()
1.1,1
2.1,2
3.2,3
4.2,2
Ans: 3
13.What is the output of relational
operator?
Ans: Boolean(true, false)
14.Which among the following falls under key
elements of programming?
1.Good analytical skills
2.Declarative knowledge
3. imperative knowledge
4.Abstraction knowledge in programming
Ans: 1, 2, 3, 4
15.What is the extension of java code files?
1..java
2..class
3.Both 1 and 2
4..txt
Ans: 1
16.Which is not OOPS concept?
1.Compilation
2.Polymorphism
3.Encapsulation
4.Inheritance
Ans: 1
17.Which component is used to compile, debug
and execute java program?
1.JIT
2.JRE
3.JVM
4.JDK
Ans: 4
18.What is the extension of compiled
java classes?
1..java
2..txt
3..class
Ans: 3
19.Which of these can not be used for a variable
name in java?
1.Identifier & keyword
2.Keyword
3.Identifier
4.None of these
Ans: 2
20.expression1 ? expression2
:expression3|what it will return?
1.Float
2.Integer
3.Boolean
Ans:3
21.Which of these is long data type
literal?
1.0x99fffa
2.0x99fffL
3.99671246
Ans: 2
22.Which of these is superclass of every
class?
1.String class
2.Object class
3.Abstract class
4.ArrayList class
Ans: 2
23.Which of these keywords can be used to
prevent inheritance of a class?
1.Constant
2.Class
3.Super
4.Final
Ans: 4
BONUS QUESTION
1. what is the output?
public static void main(String[] args)
{
int var1=1;
if (var1)
{
System.out.println("Inside If Condition");
}

}
a)Inside If Condition
b)does not print anything
c)Compilation Error
d)Run Time Error
Ans: c (var1 is int not boolean)(var1==1)
2.what is the output?
public static void main(String[] args)
{
int var1;
if (var1==0)
{
System.out.println("Inside If Condition");
}

}
a) Inside If Condition
b) does not print anything
c) Compilation Error
d) Run Time Error
Ans: c (var1 need to be initialized)
3.What modifier can be used to prevent any method or
attribute to be not visible to external classes?
a. Private
b. Public
c. Protected
d. Default
Ans: a
4.What modifier can be used to restrict a
method or attribute to be invisible outside its
package?
a. Private
b. Public
c. Protected
d. Default (No modifier)
Ans: d
5.If package name containing more than one
word is used, the words must be separated by
a. comma
b. dot
c. hyphen
d. underscore
Ans: b
6.All the classes in a package can be
simultaneously imported by using
__*__ wildcard
7. Which of the following statement declares an int
array of size 10?
a)int[10] array
b)int array[10]
c)int[] array = new int[10](answer)
d)int[10] array = new int[10]
e)int[] array = new int[10]{}
Ans: c or int[] array = new int[]{1,2,3}

You might also like