• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Java language fundamentals
 

Java language fundamentals

on

  • 1,066 views

Java, Java language fundamentals, Frequently asked questions in technical aptitude. SCJP Dumbs.

Java, Java language fundamentals, Frequently asked questions in technical aptitude. SCJP Dumbs.

Statistics

Views

Total Views
1,066
Views on SlideShare
1,066
Embed Views
0

Actions

Likes
0
Downloads
79
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Java language fundamentals Java language fundamentals Presentation Transcript

    • Language Fundamentals Duration 1 Hr.
    • Question 1An object isSelect 1 correct option.a what classes are instantiated from.b an instance of a class.c a blueprint for creating concrete realization of abstractions.d a reference to an attribute.e a variable.Ans: b
    • Question 2What will the following code snippet print?int index = 1; String[] strArr = new String[5]; String myStr = strArr[index]; System.out.println(myStr);Select 1 correct option.A It will print nothing.B It will print nullC It will throw ArrayIndexOutOfBounds at runtime.D It will print NullPointerException at runtime.E None of the above.Ans: b
    • Question 3In which of these variable declarations, will the variable remain uninitializedunless explicitly initialized?Select 1 correct option.a Declaration of an instance variable of type int.b Declaration of a static class variable of type float.c Declaration of a local variable of type float.d Declaration of a static class variable of class Objecte Declaration of an instance variable of class Object.Ans: c
    • Question 4What is the range of a char data type?Select 1 correct option.a 0 - 65, 535b 0 - 65, 536c -32,768 - 32,767d 0 - 32,767e None of the aboveAns: a
    • Question 5What will the following program print?public class TestClass{ public static void main(String[] args) { unsigned byte b = 0; b--; System.out.println(b); }}Select 1 correct option.A0B -1C 255D -128E It will not compile.Ans: e unsigned
    • Question 6Carefully examine the following code.public class StaticTest{ static { System.out.println("In static"); } { System.out.println("In non - static"); } public static void main(String args[ ]) { StaticTest st1; //1 System.out.println(" 1 "); st1 = new StaticTest(); //2 System.out.println(" 2 "); StaticTest st2 = new StaticTest(); //3 }}What will be the output?Select 1 correct option.a In static, 1, In non - static, 2, In non - static : in that order.b Compilation error.c 1, In static, In non - static, 2, In non - static : in that order.d In static, 1, In non - static, 2, In non - static : in unknown order.e None of the above.Ans: a
    • Question 7What will happen when you compile and run the following program using thecommand line:java TestClass 1 2public class TestClass{ public static void main(String[] args) { int i = Integer.parseInt(args[1]); System.out.println(args[i]); }}Select 1 correct option.a Itll print 1b Itll print 2c Itll print some junk value.d Itll throw ArrayIndexOutOfBoundsExceptione Itll throw NumberFormatExceptionAns: d
    • Question 8Which of the following are valid at line 1?public class X{ line 1: //put statement here.}Select 2 correct optionsa String s;b String s = asdf;c String s = a;d String s = this.toString();e String s = asdf;Ans: a&d
    • Question 9A method is ..Select 1 correct option.a an implementation of an abstraction.b an attribute defining the property of a particular abstraction.c a category of objects.d an operation defining the behavior for a particular abstraction.e a blueprint for making operations.Ans: d
    • Question 10An instance member ...Select 2 correct optionsa can be a variable, constant or a method.b is a variable or a constant.c Belongs to the class.d Belongs to an instance of the class.e is same as a local variable.Ans: a&d
    • Question 11Given the following class, which of these given blocks can be inserted at line1 without errors?public class InitClass{ private static int loop = 15 ; static final int INTERVAL = 10 ; boolean flag ; //line 1}Select 4 correct optionsa static {System.out.println("Static"); }b static { loop = 1; }c static { loop += INTERVAL; }d static { INTERVAL = 10; }e { flag = true; loop = 0; }Ans: a,b,c,e
    • Question 12Which of the following are correct ways to initialize the static variables MAX and CLASS_GUID ?class Widget{ static int MAX; //1 static final String CLASS_GUID; // 2 Widget() { //3 } Widget(int k) { //4 }}Select 2 correct optionsa Modify lines //1 and //2 as : static int MAX = 111; static final String CLASS_GUID = "XYZ123";b Add the following line just after //2 : static { MAX = 111; CLASS_GUID = "XYZ123"; }c Add the following line just before //1 : { MAX = 111; CLASS_GUID = "XYZ123"; }d Add the following line at //3 as well as //4 : MAX = 111; CLASS_GUID = "XYZ123";e Only option 3 is valid.Ans: a,b
    • Question 13What will be the result of attempting to compile and run the following class?public class TestClass{ public static void main(String args[ ] ) { int i = 1; int[] iArr = {1}; incr(i) ; incr(iArr) ; System.out.println( "i = " + i + " iArr[0] = " + iArr [ 0 ] ) ; } public static void incr(int n ) { n++ ; } public static void incr(int[ ] n ) { n [ 0 ]++ ; }}Select 1 correct option.a The code will print i = 1 iArr[0] = 1;b The code will print i = 1 iArr[0] = 2;c The code will print i = 2 iArr[0] = 1;d The code will print i = 2 iArr[0] = 2;e The code will not compile.Ans: b
    • Question 14Consider the following code snippet ...boolean[] b1 = new boolean[2];boolean[] b2 = {true , false};System.out.println( "" + (b1[0] == b2[0]) + ", "+ (b1[1] == b2[1]) );What will it print ?Select 1 correct option.a It will not compile.b It will throw ArrayIndexOutOfBoundsError at Runtime.c It will print false, true.d It will print true, false.e It will print false, false.Ans: c
    • Question 15What will the following program print?public class TestClass{ static String str; public static void main(String[] args) { System.out.println(str); }}Select 1 correct option.a It will not compile.b It will compile but throw an exception at runtime.c It will print nulld It will print nothing.e None of the above.Ans: c
    • Question 16public class TestClass{ public static void main(String[] args) { String tom = args[0]; String dick = args[1]; String harry = args[2]; }}What will the value of harry if the program is run from the commandline:java TestClass 111 222 333Select 1 correct option.a 111b 222c 333d It will throw an ArrayIndexOutOfBoundsExceptione None of the above.Ans: c
    • Question 17Which of these are keywords in Java?Select 3 correct optionsa defaultb NULLc Stringd throwse longAns: a,d,e
    • Question 18Which of the following are valid identifiers?Select 2 correct optionsa classb $value$c angstromd 2muche zer@Ans: b,c
    • Question 19public class TestClass{ public static void main(String[] args) { String str = "111"; boolean[] bA = new boolean[1]; if( bA[0] ) str = "222"; System.out.println(str); }}What will the above program print?Select 1 correct option.a 111b 222c It will not compile as bA[0] is uninitialized.d It will throw an exception at runtime.e None of the above.Ans: a
    • Question 20What will be the output of the following lines ?System.out.println("" +5 + 6); //1System.out.println(5 + "" +6); // 2System.out.println(5 + 6 +""); // 3System.out.println(5 + 6); // 4Select 1 correct option.a 56, 56, 11, 11b 11, 56, 11, 11c 56, 56, 56, 11d 56, 56, 56, 56e 56, 56, 11, 56Ans: a
    • Question 21Which of the following is not a primitive data value in Java?Select 2 correct optionsa "x"b xc 10.2Fd Objecte falseAns: a,d
    • Question 22What does the zeroth element of the string array passed to the standard mainmethod contain?Select 1 correct option.a The name of the class.b The string "java".c The number of arguments.d The first argument of the argument list, if present.e None of the above.Ans: d
    • Question 23What will the following program print?public class TestClass{ static boolean b; static int[] ia = new int[1]; static char ch; static boolean[] ba = new boolean[1]; public static void main(String args[]) throws Exception { boolean x = false; if( b ) { x = ( ch == ia[ch]); } else x = ( ba[ch] = b ); System.out.println(x+" "+ba[ch]); }}Select 1 correct option.a true trueb true falsec false trued false falsee Itll not compile.Ans: d
    • Question 24What will be the result of attempting to compile and run the following code?public class InitClass{ public static void main(String args[ ] ) { InitClass obj = new InitClass(5); } int m; static int i1 = 5; static int i2 ; int j = 100; int x; public InitClass(int m) { System.out.println(i1 + " " + i2 + " " + x + " " + j + " " + m); } { j = 30; i2 = 40; } // Instance Initializer static { i1++; } // Static Initializer}Select 1 correct option.a The code will fail to compile, since the instance initializer tries to assign a value to a static member.b The code will fail to compile, since the member variable x will be uninitialized when it is used.c The code will compile without error and will print 6, 40, 0, 30, 5 when run.d The code will compile without error and will print 5, 0, 0, 100, 5 when run.e The code will compile without error and will print 5, 40, 0, 30, 0 when run.Ans: c
    • Question 25Which code fragments will print the last argument given on the command line to the standard output, and exit without any output andexceptions if no arguments are given?1. public static void main(String args[ ]) { if (args.length != 0) System.out.println(args[args.length-1]); }2.public static void main(String args[ ]){ try { System.out.println(args[args.length-1]); } catch (ArrayIndexOutOfBoundsException e) { }}3. public static void main(String args[ ]) { int i = args.length; if (i != 0) System.out.println(args[i-1]);}4.public static void main(String args[ ]){ int i = args.length-1; if (i > 0) System.out.println(args[i]);}5. public static void main(String args[ ]) { try { System.out.println(args[args.length-1]); } catch (NullPointerException e) {} }Select 3 correct optionsa Code No. 1b Code No. 2c Code No. 3d Code No. 4e Code No. 5Ans: a,b,c
    • Question 26Consider the following class:public class ArgsPrinter{ public static void main(String args) { for(int i=0; i<3; i++) { System.out.println(args); } }}What will be printed when the above class is run using the following command line:java ArgsPrinter 1 2 3 4Select 1 correct option.a123b ArgsPrinter 1 2c java ArgsPrinter 1 2d111e None of these.Ans: e
    • Question 27Consider the following class definition:public class TestClass{ public static void main(){ new TestClass().sayHello(); } //1 public static void sayHello(){ System.out.println("Static Hello World"); } //2 public void sayHello() { System.out.println("Hello World "); } //3}What will be the result of compiling and running the class?Select 1 correct option.a It will print Hello World.b It will print Static Hello World.c Compilation error at line 2.d Compilation error at line 3.e Runtime Error.Ans: b
    • Question 28What will the following program print?public class TestClass{ static int someInt = 10; public static void changeIt(int a) { a = 20; } public static void main(String[] args) { changeIt(someInt); System.out.println(someInt); }}Select 1 correct option.a 10b 20c It will not compile.d It will throw an exception at runtime.e None of the above.Ans: a
    • Question 29What is the numerical range of short data type?Select 1 correct option.a It depends on the platform the JVM is running.b 0 to 65535c -32768 to 32767d 0 to 32767e -16384 to 16383Ans: c