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

HOME
anilbachi SCJP Practice Exams

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

chapter7 | chapter8 | chapter9 | chapter10 | chapter11 |

chapter 1: Language Fundamentals Questions

Q1: Which of the following are the correct form of documentation comments?

a]. //some text here

b]. /*some text here*/

c]. /**some text here*/

d]. all the above

 

Q2: State the correct formula for minimum/maximum values for integer primitives

a] 2^(no_of_bits-1) / 2^(no_of_bits-1)+1

b] 2^(no_of_bits+1) / 2^(no_of_bits+1)+1

c] 2^(no_of_bits-1) / 2^(no_of_bits-1)-1

d] all the above

 

Q3: When you use a web browser to browse the javadoc information for a package, how are the list of classes in that package organized?

a]. according to the class hierarchy

b]. alphabetically by class name

c]. by frequency of use

d]. all the original java1.0 classes comes first, followed by the classes added for the java1.1 and 1.2 releases

 

Q4: Which color is used to indicate instance methods in the standard 'javadoc' format documentation

a]. blue

b]. red

c]. purple

d]. orange

 

Q5: which of the following is the correct way to define a class that will be in the default package

a]. package default;

import java.util.*;

b]. import java.util.*;

package default;

c]. import java.util.*;

d]. all the above

 

Q6: Which of the following main method in a java application is correct?

a]. public static void main(string[] args)

b]. public void main(String args[])

c]. public static void main (string[] args)

d]. both a and c

e]. static public void main(String x[])

f]. a, c and e.

 

Q7: Which of the following is default integer primitive

a]. short

b]. int

c]. byte

d]. char

e]. long

 

Q8: Which of the following integer primitive types can correctly represent a value of 65,000

a]. short

b]. int

c]. byte

d]. long

e]. char

f]. both b and d

g]. a, b and d

 

Q9: Which of the following is not a reserved word in java

a]. import

b]. finally

c]. friend

d]. goto

 

Q10: When writing a utility class, someclass, which extends mainclass class and will be used by several other classes in a large project. These other classes will be in different packages.Pick the correct class declaration.

a]. class someclass extends mainclass

b]. protected class someclass extends mainclass

c]. public class someclass extenda mainclass

d]. none

 

Q11: Which of the following variable names are invalid?

a) example

b). 2sumup

c). its4u

d). $money

 

Q12:Which of the following initializes boolean primitive?

a). Boolean flag=true;

b). boolean flag=true;

c). boolean flag=TRUE;

d). Boolean flag=TRUE;

 

Q13: Take a look at the following main method.

public static void main (String[] args){

System.out.println(args[1];.

}

The above is executed by the following command line.

java test one two three four

choose the correct output

a). one

b). two

c). three

d). four

e). none

 

Q14: Which of the following value is a byte primitive?

a). 129

b). -129

c). 128

d). 127

 

Q15: Select the correct statements?

a). char and int primitives are 16 bit

b). int and float are 32 bit

c). float and double are 64 bit

d). long and double are 64 bit

 

Q16: Which of the following is not a valid top level class?

a). public class topclass

b). static class topclass

c). private class topclass

d). all the above

e). a and b

 

Q17: An example unicode value is '0x3c0' in hexadecimal.

Which of the following correctly initializes the char primitive to the pi?

a). char pi='u3c0';

b). char pi='\u03c0';

c). char pi="\u03c0";

d). char pi='\x03c0';

 

Q18: State the reason for a compile error caused by the following statement

String name="summertime \u00d wintertime";

a]. escape sequences for unicode characters should not be embedded in String literals

b]. escape sequences inserts the code for a line terminator. Line terminators are not allowed between opening and closing quotes

c]. '\u00d' is not a valid unicode character

d]. none of the above

 

Q19: The term deprecated refers to the classes and methods that are not safe to use

a]. true

b]. false

 

Q20: Number of bits in a java double primitive

a]. 0 bits

b]. 48 bits

c]. 32 bits

d]. 64 bits

 

Q21: Which of the following is true

a]. a class level int primitive is automatically initialized to 0

b]. a class level boolean primitive is automatically initialized to false

c]. a local boolean primitive is automatically initialized to false

d]. all the above

 

Q22: An automatic variable becomes eligible for garbage collection when it goes out of scope

a]. true

b]. false

 

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

 

Click here for solutions

 

 

©Copyrights anilbachi.8m.com All rights reserved

for queries contact anil_kuchana@yahoo.com