Test Your Java 1

Test Your Java 1

Test Your Java 7 and Test Your Java 8 are advanced questions. Answers are given for each question at the end of each test. Answering these questions increases your knowledge in Java and helps you a lot when you appear for interviews. Solving these basic questions is your first step for Certification Exams preparation.

Test Your Java – 1

Read all the choices carefully, as there may be more than one correct answer, choose all the correct answers for each question.

  1. ________________________ makes Java platform-independent.
    a) JVM b) Java syntax c) Java API d) bytecodes e) none
  2. Java's keywords includes Null.
    a) True b) False
  3. Which occupies more number of bits of memory.
    a) double b) long c) both 4 b) occupies same d) depends on the value assigned e) none
  4. The object is created with new keyword
    a) at compile-time b) at run-time c) depends on the code d ) none
  5. int x = 0, y = 0 , z = 0 ;
    x = (+ + x + y – – ) * z + + ;
    What is the value of " x " after execution ?
    a) – 2 b) – 1 c) 0 d ) 1 e) 2
  6. int 4thhouse = 1234 ;
    System.out.println( 4thhouse ) ;
    a) 1234 b) displays error as the value assigned is more than the range of integer c) displays error as coding is not as per Java rules e) none
  7. int ++a = 100 ; System.out.println( ++a ) ;
    What is the output of the above fraction of code ?
    a) 100 b) displays error as + + a is not enclosed in double quotes in println statement c) compiler displays error as + + a is not a valid identifier d) none
  8. Integer.parseInt( ) method is used to convert an integer value to its string form.
    a) True b) False
  9. Java supports unsigned data types.
    a) True b) False
  10. One way of implementing data protection is declaring instance variables as private and methods as public.
    a) True b) False
  11. How many primitive data types Java defines ?
    a) 6 b) 8 c) 10 d) more than 10 e) none
  12. The variables declared in a class for the use of all methods of the class are called
    a) reference variables b) objects c) instance variables d ) none
  13. double STATIC = 2.5 ;
    System.out.println( STATIC ) ;
    The above fraction of code
    a) prints 2.5 b) raises an error as STATIC is used as a variable which is a keyword c) raises an exception e) none
  14. What is the range of data type int ?
    a) – ( 2^16 ) to ( 2^16 ) –1 b) – ( 2^15 ) to ( 2^15 ) –1 c) – ( 2^31 ) to ( 2^31 ) –1 d) – ( 2^32 ) to ( 2^32 ) –1 e) depends on the operating system on which Java is working f) none
  15. int Integer = 34 ;
    char String = 'S' ;
    System.out.println( Integer ) ;
    System.out.println( String ) ;
    What would be the output of the above fraction of code ?
    a) does not compile as Integer and String are API class names b) throws exception c) 34 d) S e) c and d f) none
  16. char k = 'A' ;
    System.out.println( k * k ) ;
    The above program raises a compilation error as arithmetic operations are not possible on characters. a) true b) false
  17. System.out.println( Math.floor( Math.random( ) ) ) ;
    The above statement always prints 0.0
    a) True b) False
  18. int x = 99 , y = 100 ;
    System.out.println( x / y ) ;
    What is the output of the above fraction of code ?
    a) does not compile b) 0 c) 0.99 d) none
  19. boolean b = true ;
    int i = ( int ) b ;
    System.out.println( i ) ;
    What is the output of the above fraction of code ?
    a) 116 ( the ASCII value of character t ) b) 98 ( the ASCII value of character b ) c) does not compile d) throws exception e) none
  20. System.out.println(25/4.0);
    System.out.println(25.0/4.0);
    System.out.println(25.0/4);
    The output of the above three println statements is same result.
    a) True b) False
  21. 21.


  22. What is the output of the above program ?
    a) 0 b) 2.0 c) error as mismatch between constructors d) none
  23. byte b = 50 ;
    b = b * 2 ;
    System.out.println( “ b = “ + b ) ;
    The above fraction of code prints b = 100.
    a) True b) False
  24. 23.

  25. What is the output of the above program ?
    a) 20 b) 21 c) 22 d) does not compile e) throws exception e) none ( )
  26. Constructors can be declared final, if needed perhaps which you must have not tried.
    a) True b) False
  27. final methods cannot be overridden but overloaded ?
    a) True b) False

ANSWERS

1. d 2. b 3. c 4. b 5. c
6. c 7. c 8. b 9. b 10. a
11. b 12. c 13. a 14. c 15. e
16. b 17. a 18. b 19. c 20. a
21. c 22. b 23. c 24. b 25. a

Your Rating

Correct Answers
1 to 5 : Poor
6 t0 10: Below average
11 t0 15: Average
16 to 20: Good
Above 20: Extraordinary

Pass your comments and suggestions for the improvement of this "Test Your Java 1".

40 thoughts on “Test Your Java 1

  1. asif

    Sir,Is Java pure object oriented as my sir told us,n if not then please give me reason for it.or any blog you have related to it.

    1. S. Nageswara Rao, Corporate Trainer Post author

      9) Java does not support “unsigned” datatypes for that matter “unsigned” is not keyword of Java. “char” is implicitly unsigned.

      Java does support pointers and it does not mean the designers should not use pointers in developing the language.

      20) The output is same answer of division quotient.

      Remember these questions for very beginners. If you think of Strings and String pools, I will modify the question for you and pass your comments.

      1. Petr Gangnus

        Than for 9 the question should sound as “Is a word ‘unsigned’ used for some Java types definition?”

        As for 20, you haven’t understood. The outputs include strings “20/4.0” and “20.0/4” And they ARE different. But, as I see, you have changed them already. Thank you.

      1. Petr Gangnus

        Because you have created the instance just here. You can’t see it from another static method.

        The variables seen from anywhere in the class are called Static Class attributes or Static Class Fields or Static Class Variables.

  2. VenkataNaveen

    Respected sir

    Recently i attended a interview where people asked some questions like Difference between ByteArrayOutStream and BufferedOutputStream and where do we use them ?

    so please post a detailed explanation to this to give us some in depth idea on this

    Thanks in advance

    Thanks and Regards
    Venkata Naveen

  3. harshitha

    interface Side {
    String getSide();
    }
    class Head implements Side {
    public String getSide()
    {
    return “Head “; }
    }
    class Tail implements Side {
    public String getSide()
    {
    return “Tail “; }
    }
    class Coin {
    public static void overload(Head side) { System.out.print(side.getSide()); }
    public static void overload(Tail side) { System.out.print(side.getSide()); }
    public static void overload(Side side) { System.out.print(“Side “); }
    public static void overload(Object side) { System.out.print(“Object “); }
    public static void main(String []args) {
    Side firstAttempt = new Head();
    Tail secondAttempt = new Tail();
    overload(firstAttempt);
    overload((Object)firstAttempt);
    overload(secondAttempt);
    overload((Side)secondAttempt);
    }
    }

    sir can u please explain this program .In main,how can overload(firstAttempt); wil call overload(Side side) method?and even explain when we call
    overload((Object)firstAttempt);
    overload(secondAttempt);
    overload((Side)secondAttempt);,which methods are called?

  4. harshitha

    class Base {
    public static void foo(Base bObj) {
    System.out.println(“In Base.foo()”);
    bObj.bar();
    }
    public void bar() {
    System.out.println(“In Base.bar()”);
    }
    }
    class Derived extends Base {
    public static void foo(Base bObj) {
    System.out.println(“In Derived.foo()”);
    bObj.bar();
    }
    public void bar() {
    System.out.println(“In Derived.bar()”);
    }
    }
    class OverrideTest {
    public static void main(String []args) {
    Base bObj = new Derived();
    bObj.foo(bObj);
    }
    }

    sir! can you please explain how can bobj object call foo() method of base class?as sub class obj is assigned to super class object,the object should call sub class overidden method as per rules!

  5. Pawan Kalyan

    int ++a = 100 ; System.out.println( ++a ) ;
    What is the output of the above fraction of code ?
    a) 100
    b) displays error as + + a is not enclosed in double quotes in println statement
    c) compiler displays error as + + a is not a valid identifier
    d) none

    Answer: C

    Sir Explain this.

  6. Pawan Kalyan

    byte b = 50 ;
    b = b * 2 ;
    System.out.println( “ b = “ + b ) ;
    The above fraction of code prints b = 100.
    a) True b) False

    Answer is false.

    Sir, Please explain this.

  7. RamReddy

    char k = ‘A’ ;
    System.out.println( k * k ) ;
    The above program raises a compilation error as arithmetic operations are not possible on characters. a) true b) false

    answer 9409,,, there is no compilation error ,it prints some integer value
    tel me sir why it is taken integer value?

  8. Sandeep

    int Integer = 34 ;
    char String = ‘S’ ;
    System.out.println( Integer ) ;
    System.out.println( String ) ;
    What would be the output of the above fraction of code ?
    a) does not compile as Integer and String are API class names b) throws exception c) 34 d) S e) c and d f) none

    how it is working String is a Data Type how ur using Integer and String as a Variable i cant believe , please explain me in detail sir

  9. vikas

    in ques 21 there is error that it is not finding the constructor if you perform this in notepad in wind 7 becouse parametrized constructor are never inherited but if you perform that in eclipse it is showing the result ….. sir plz tell me why its happening

        1. Shrutika

          as the super class is having parameterised constructor and object of Num class is created using parameterised constructor what is the need of default constructor?

Leave a Reply

Your email address will not be published. Required fields are marked *