Java Test
Java Test
Test
-----------------------------------------------------------------------------------
1)
the java development tools under JDK are…?
a)javac b)javam c)java d)javar
2)
Which compiler produces native code from java byte code
instructions during program execution.
a)JVM b)JIT c)JAVAC d)JAVA
3)
What's the history of java?
a)in 1990,sun microsystem ,games josling
b)in 1991,sun microsystem ,james gosling
c)in 1995,sun microsystem ,james josling
d)in 1995,sun microsystem ,james gosling
4)
What's the true statement about a identifier..choose any
two..
a)An identifier must begin with a letter,a hyphen or a
dollar symbol.
b)identifier can include numbers,but cannot begin with a
number.
c)an identifier must begin with a letter, or underscore
d)we can use any special character while declaring an
identifier.
5)
what's the output...
class hello
{
public static void main(String argsp[]){
float num=10.5f;
double num1=10.5;
if(num1==num){
System.out.println("num is not equal to num1");}else{
System.out.println("num1 is equal to num");
}}}
a)num1 is equal to num
b)error
c)num is not equal to num1
d)data type must be same so output will be nothing.
6)
what will be the output?
class abc{
public static void main(String args[]){
int i=1,sum=0;
while(i<500)
{
sum=sum+i;
System.out.println("sum:"+sum);
i++;
if(i==10)break;}}}
7)
what will be the output?
class xyz{
public static void main(String args[]){
A a=new A();
a.fun2();
B b=new B();
b.fun2();}}
class A{
public void fun1(){System.out.println(“hello”);}
final public void fun2(){System.out.println(“how r you”);}}
class B extends A{
public void fun1(){System.out.println(“hi”);}
public void fun2(){System.out.println(“fine”);}}
a)how r you b)error
fine
c)fine d)None
how r you
8)
Which keyword indicates that it is a class method and can
be accessed without creating an object.
a)void b)static c)return d)public
9)
Which member of a class is accessible only to the
members of the class and not to the non-members of the class.
a)private b)public c)protected
d)abstract
11)
What is the superclass of the class throwable?
a)exception b)error c)object d)runtime
exception
12)
What will be the output?
Class sampleswitch{
Public static void main(String args[]){
For(int i=0;i<6;i++)
{
switch(i){
Case 0:
System.out.println(“I is zero”);break;
Case 1: System.out.println(“I is 1”);break;
Case 2: System.out.println(“I is 2”);break;
Case 3: System.out.println(“I is 3”);break;
Default:System.out.println(“I is greater than 3”);
}}}
a)i is zero
I is 1
I is 2
I is greater than 3
b)error
c)i is zero
I is 1
I is 2
I is 3
I is greater than 3
d)i is zero
I is 1
I is 2
I is 3
I is greater than 3
I is greater than 3
I is greater than 3
13)
class usestatic
{ int a=3;
static int b;
static void meth(int x)
{
System.out.println(“x=”+x);
System.out.println(“a=”+a);
System.out.println(“b=”+b);
public static void main(String args[]){
meth(42);
}}
a)x=42,a=3,b=12
b)error
c)x=42,a=0,b=3
d)x=42,a=3,b=0
14)
What will be the output?
class A{
A()
{
System.out.println(“inside A constructor”);
}}
class B extends A{
B(){
System.out.println(“inside B constructor”);
}}
class C extends B{
C(){
System.out.println(“inside C constructor”);
}}
class hello{
public static void main(String args[]){
C c=new C();}}
a)inside B constructor
inside C constructor
inside A constructor
b)inside A constructor
inside B constructor
inside C constructor
c)inside C constructor
inside A constructor
inside B constructor
d)inside A constructor
inside C constructor
inside B constructor
15)
Can interface be extended?
A)yes b)no
16)
Identify the correct statement for displaying a message on
the screen.
a)System.out.println(“I m java expert”);
b)System.out.Println(“I m java expert”);
c)system.out.println(“I m java expert”);
d)System.out.println(‘I m java expert”);
17)
Which of the following keywords is used to terminate the
loop statements
a)break b)exit c)end d)terminate
18)
Which of the folloeing loops gets executed at least once,no
matter what the test condition is?
a)while b)do-while c)for d)for-each
19)
What is the output of the following code?
class test{
public static void main(String args[]){
int ctr=3;
int result=1;
while(ctr>1){
result=result*ctr;
ctr--;}
System.out.println(result);
}}
a)6 b)3 c)1 d)0
20)
------is defined to initialize its member variables.
a)method b)main()
c)constructor d)objects
21)
The ______keyword is used to call the parent class
constructor.
a)base b)super c)this d)extends
22)
In java ,when two or more methods are defined in a class
with the same name but different parameters lists,it is called
a)inheritance
b)method overloading
c)method overriding
d)constructor
23)
In java,the byte data type has a range from ----------
to--------------
a)-32767 to 32768
b)-32768 to 32767
c)-127 to 127
d)-128 to 127
24)
Which of the following are legal identifiers.
a)Tel_num
b)emp1
c)8678
d)batch.no
25)
What is the output of the following code?
class you{
public static void main(String args[])
{int sales=3500;
int profit=800;
System.out.println((sales+profit)/10*5);
}}
a)2150
b)1250
c)5210
d)2510