Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

anilbachi SCJP Practice Exams

chapter1 | chapter2 | chapter3 | chapter4 | chapter5 | chapter6 |

chapter7 | chapter8 | chapter9 | chapter10 | chapter11 |

chapter 1: Language Fundamentals Questions ( page 3of 3 )

Page1 | page 2

Q23: Choose the correct applicable statement for the following code fragment

1.String countries[];

2.countries[0]="india";

a]. no error occurs

b]. compile time error occurs because the countries array object has not been created

c]. runtime error occurs because the countries array object has not been created

 

Q24: A class contains the following declarations of an instance variable

boolean flags[]=new boolean[100];

the value of flags[0] is

a]. true

b]. null

c]. false

d]. none

 

Q25: Which of the following are keywords in java. Select all the correct answers

a]. friend

b]. NULL

c]. implement

d]. synchronized

e]. throws

 

Q26: Using upto 4 characters write java representation of the octal literal 6

 

Q27: Using upto 4 characters write java representation of the integer literal 10 in hexadecimal

 

Q28: What would happen when the following is compiled and executed. Select the one correct answer

public class compare{

public static void main(String args[]){

int X=10,y;

if(X<10) y=1;

if(X>=10) y=2;

System.out.println("y is "+y);

 

a]. the program compiles and prints y is 0 when executed

b]. the program compiles and prints y is 1 when executed

c]. the program compiles and prints y is 2 when executed

d]. the program does not compile complaining about y not being initialized

e]. the program throws a runtime exception

 

Q29: What would happen when the following is compiled and executed select the correct answer

class example{

int X;

int Y;

String name;

public static void main(String args[]){

example pnt=new example();

System.out.println("pnt is"+pnt.name+" "+pnt.X+" "+pnt.Y);

a]. the program does not compile because X,Y and name are not initialized

b]. the program throws a runtime exception as X,Y and name are used before initialization

c]. the program prints pnt is 0,0

d]. the program prints pnt is null, 0, 0

e]. the program prints pnt is NULL, false, false

 

Q30: Which of the following statements are correct

a]. a java program must have a package statement

b]. a package statement if present must be the first statement in the program

c]. if a java program defines both the package and import statement, then the import statement must come before the package statement

d]. an empty file is a valid source file

e]. a java file without any class or interface statements can also be compiled

f]. if an import statement is present, it must appear before any class or an interface definitions

 

Q31: What would be the result of compiling and running the following class

class test{

public static void main(){

System.out.println("test");

}

}

a]. the program does not compile as there is no main method defined

b]. the program compiles and runs generating an output of "test"

c]. the program compiles and runs but does not generate any output

d]. the program compiles but does not run

 

Q32: State the output when the following class is executed by entering "java test lets see what happens"

public class test{

public static void main(String args[]){

System.out.println(args[0]+" " +args[args.length]);

}}

a]. the program will print "java test"

b]. the program will print "java happens"

c]. the program will throw an ArrayIndexOutOfBounds exception

d]. none

 

Q33: Which of the following is the correct place for a documentation comments.

a). after package and before input statements.

b). before any statement in the program

c). before a class, interface, method or field

d). All the above

Page1 | page 2

 

Click here for solutions

468x60 Animated

 

©Copyrights anilbachi.8m.com All rights reserved

for queries contact anil_kuchana@yahoo.com