20 Questions

Java se 8 programmer 1 Quiz

1 :-

Given the code fragment:

int array 1 [ ] = { 1, 2, 3} ;

int array 2 [ ] = new int [ 5 ] ;

array 2 = array 1 ;

for ( int i = array 2 ) ;

system . out . print ( i + “” ) :

}

system . out . println () ;

int array 3 = new int ( 3 ) ;

array 3 = array 2 ;

for ( int i = array 3 ) ;

system . out . print ( i +"" ) ;

}

What is the result?

 

2 :-

Given:

class alpha {

int ns ;

static int s ;

 alpha ( int ns ) {

if ( s < ns ) {

s= ns ;

this . ns = ns ;

}

}

void do print {

system . out .println ( “ ns ” = + ns + “s = ” + s) ;

}

}

and

 public class test a {

public static void main ( string [ ] args ) {

alpha ref 1  = new alpha ( 100) ;

alpha ref 3 = new alpha ( 50) ;

alpha ref 3 = new alpha ( 125) ;

ref 1 =. do print ();

ref2. do print () ;

ref 3 . do print () ;

What is the result?

a) ns = 100 125

ns=0s = 125

ns = 125s =125

b) ns = 50 s = 125

    ns = 0s =125

c) ns= 50 s = 50

ns = 125 s =125

ns = 100s = 100

d) ns = 50 s = 50

    ns = 125 s = 125

   ns = 0s = 125

 

3 :-

Given the code snippet from a compiled Java source file:

public class my file 

{

public static void main ( string [] args )

}

STRING ARGS 1 = ARGS [ 1 ] ;

STRING ARGS 2 = ARGS [ 2 ] ;

STRING ARGS 3 = ARGS [ 3 ] ;

SYSTEM . OUT . PRINTLN ( “ ARG IS ” + ARG 3 ) ;

}
}

Which command-line arguments should you pass to the program to obtain the following output? 

Arg is 2

4 :-

PUBLIC CLASS SUM TEST {

PUBLIC STATIC VOID DO SUM ( INTEGER X , INTEGER Y ) ;

SYSTEM . OUT . PRINTLN ( “ INTEGER SUM IS ” + ( “ X , Y ” ) ) ;

}

PUBLIC STATIC VOID DO SUM ( DOUBLE X , DOUBLE Y ) {

SYSTEM . OUT . PRINT LN ( “ DOUBLE SUM IS ” + ( X + Y ) ) ;

}

PUBLIC STATIC VOID DOSUM ( FLOAT X , FLOAT Y ) {

SYSTEM . OUT . PRINTLN ( “ FLOAT SUM IS ” + ( X + Y ));

}

What is the result?

 

5 :-

Given the code fragment:

int x = 100;

int a = x++;

int b= ++x;

int c = x++;

in d = ( a< b) ? ( a< c) ? a: ( b<c) ? B: C: X :

system . out . println ( d) ;

What is the result?

 

6 :-

Which statement is true about the main() method?

7 :-

Given the code fragment:

public static void main ( string [] args ) {

short s1 =200;

integer s2 = 400;

long s3 =(long)s1 +s2 ;

string s4 =(string ) (s3 *s2) ;

system . out . println ( “ sum is ” +s4 ) ;

}

What is the result?

 

8 :-

Which code snippet can be inserted to print Fly.Dance. ?

 

9 :-

Which is true?

 

10 :-

Given:

public class product {

int id ;

string name ;

public product ( int id , string name ) {.

this . id = id ;

this name = name ;

}
}

and give the code fragment ;

4.product p1 = new product ( 101, “ pen ” ) ;

5. product p2 = new product ( 101, “ pen ” ) ;

6. product p3 = p1 ;

7. bpplean ans1 = p1 ==p2 ;

8 . boolean ans 2 = p1 name equals ( p2 . name ) ;

9 . system . out . print ( ans 1 + “”+ ans2 ) ;

What is the result?

11 :-

Given:

PUBLIC CLASS TEST {

PUBLIC STATIC VOID MAIN ( STRING [] ARGS )   {

BOOLEAN A = NEW BOOLEAN ( BOOLEAN . VALUEOF ( ARGS (0 ) ) ;

BOOLEAN B = NEW BOOLEAN ( ARGS [1 ] ) ;

SYSTEM .OUT . PRINTLN ( A + “” + B) ;

}

And given the commands:

What is the result?

 

 

 

12 :-

Given:

public class test {

public static void main ( string [] args ) ;

test ts = new test () ;

system . out . print ( is available + “”);

is available =ts . dostuff);

}

public static boolean dostuff() {

return ! is available 

}

static boolean is available = false ;

}

What is the result?

 

 

13 :-

Given the code fragment

public static void main ( string [  ] args ) {

short s1 = 200;

integer s2 = 400 ;

string s2 = ( string ) ( s1 + s2 ) ; // line n1

long s4 = ( long ) s1 + s2 ;     // line n2

system . out . println ( “ sum is ” + s4 ) ;

}

What is the result?

 

14 :-

Which two code fragments cause a compilation error? (Choose two.)

 

15 :-

Which option represents the state of the num array after successful completion of the outer loop?

16 :-

Which two array initialization statements are valid? (Choose two.)

17 :-

Which two statements are true about Java byte code? (Choose two.)

 

18 :-

Given the code fragments:

INTERFACE EXPORTABLE  {

VOID EXPORT () ;

}

CLASSIC TOOL IMPLEMENTS EXPORTABLE {

PUBLIC VOID EXPORT () {
SYSTEM . OUT . PRINTLN ( “ TOOL :EXPORT ” );

}
}
CLASS REPORT TOOL EXTENDS TOOL  {

VOID EXPORT () {

SYSTEM . OUT . PRINTLN ( “ RTOOL : EXPORT ” ) ;

}

PUBLIC STATIC VOID MAIN ( STRING [ ]  ARGS )  {

TOOL BTOOL = NEW TOOL () ;

CALL EXPORT ( ATOOL ) ;

CALL EXPORT ( B TOOL) ;

}

PUBLIC STATIC VOID CALLEXPORT ( EXPORTABLE EX )   {

EX. EXPORT () ;

}
}

What is the result?

 

 

19 :-

Given the code fragment:

public static void main ( string [ ] args ) {

string str = “” ;

str , trim () ;

system . out . println ( str . equals ( “” ) + “” + ste is empty ()) ;

}

What is the result?

 

20 :-

Given this array:

int [ ] int arr= { 8, 16, 32 ,64, 128 };

Which two code fragments, independently, print each element in this array? (Choose two.)

a) FOR ( INT I = INT I : INT ARR ) {

   SYSTEM . OUT . PRINT ( INT ARR[ I] + “” ) ;

}

B) FOR ( INT I : INT ARR ) {

SYSTEM OUT . PRINT ( I + “”);

}

C) FOR ( INT I = 0 ; INT ARR) {

.   system . out . print ( int arr[ i ] + “”);

}

d) for ( int i = 0 ;  < int arr . length ; i ++ ) {

   system . out . print ( i + “”) ;

}

e ) for ( int i = 0 ; i < int arr . length ; i ++ ) {

system . out . print ( int arr [ i] + “” );

}

 

Mock Test Completion Certificate
You scored 0 out of 20 questions.

🏅

For your extraordinary service and contributions to your profession.
We are delighted in providing this certificate to you.

Tips for improving your score:

  • Make sure to read the questions and answer choices carefully.
  • Don't try to answer any choices that you don't know. It's better to skip a question.