Skip to main content

JAVA INTERVIEW QUESTIONS


JAVA INTERVIEW QUESTIONS


1.      What will be the result of attempting to compile and run the following class?
public class Assignment {
    public static void main(String[] args) {
        int a, b, c;
        b = 10;
        a = b = c = 20;
        System.out.println(a);
    }
}
  1. The code will fail to compile, since the compiler will recognize that the variable c in the assignment statement a = b = c = 20; has not been initialized.
  2. The code will fail to compile because the assignment statement a = b = c = 20; is illegal.
  3. The code will compile correctly and will display 10 when run.
  4. The code will compile correctly and will display 20 when run.

2.      Which statements are true?
a.      The result of the expression (1 + 2 + "3") would be the string "33".
b.      The result of the expression ("1" + 2 + 3) would be the string "15".
c.       The result of the expression (4 + 1.0f) would be the float value 5.
d.      The result of the expression ('a' + 1) would be the char value 'b'.

3.      What will the following program print when run?
// Filename: MyClass.java
public class MyClass {
    public static void main(String[] args) {
        B b = new B("Test");
    }
}

class A {
    A() {
       this("1", "2");
      }

    A(String s, String t) {
         this(s + t);
     }

    A(String s) {
      System.out.println(s);
     }
}

class B extends A {
    B(String s) { System.out.println(s); }

    B(String s, String t) { this(t + s + "3"); }

    B() { super("4"); };
}

Select the one correct answer.
  1. It will simply print Test.
  2. It will print Test followed by Test.
  3. It will print 123 followed by Test.
  4. It will print 12 followed by Test.

4.      Which one of these is not a legal member declaration within a class?
a.      static int a;
b.      final Object[] fudge = { null };
c.       abstract int t;
d.       native void sneeze();

5.      Which statements are true about modifiers?
a.      Fields can be declared synchronized.
b.      Non-abstract methods can be declared in abstract classes.
c.       Classes can be declared native.
d.      Abstract classes can be declared final.

6.      What is the purpose of final   variables
             
             a.      Making a constant
             b.      To hide a variable in child class
             c.       To protect from inherited classes
             d.      Making a variable of fixed memory

7.      The mother of all classes in Java
             
             a.      java.lang.Object
             b.      java.lang.Class.object
             c.       java.lang.System.Object
             d.      java.Object

8.      Java does not support

             a.      Operator overloading
             b.      Function overloading
             c.       Constructor overloading
             d.      Method overloading

9.       _________used to access the parent class members

              a.      extend
              b.      public
              c.       this
             d.      super

10.  What will be the result of attempting to compile and run the following program?
public class Polymorphism {
                     public static void main(String[] args) {
                                         A ref1 = new C();
                                           B ref2 = (B) ref1;
                                           System.out.println(ref2.f());
                     }
}
 
class A  {
                     int f() {
                     return 0;
                     }
 }
class B extends A { 
                    int f() { 
                    return 1; 
                    } 
}
class C extends B {
                     int f() { 
                    return 2; 
                    } 
}
Select the one correct answer.

a.      The program will fail to compile.
b.      The program will compile without error and print 0 when run.
c.       The program will compile without error and print 1 when run.
d.      The program will compile without error and print 2 when run.      

Popular posts from this blog

CONVERTING TORRENT FILE TO ZIP FILE

HOW TO CONVERT TORRENT FILE TO ZIP FILE 1>>click the link below  http://www.zbigz.com   2>>upload your .torrent file  3>>wait until conversion, after conversion your  file can be downloadable in .zip format.

What is the difference between Abstraction and Encapsulation?

I'm sure You came here to see the answer after vising plenty of websites and which is not enough to understand about that concept. The reason why you cant get the perfect or believable answer abut this concept is you're not reading the whole content slowly and carefully. But im sure if you read this fully and carefully, you can earn the knowledge about the difference between Abstraction and Encapsulation. and here we are gonna teach you the real time scenario of Abstraction and Encapsulation. ok!  Lets go to the Topic. What is Abstraction: "Abstraction  is a process of hiding the implementation details and showing only functionality to the user." You could see this answer in many websites. Let me explain about what is implementation and functionality.  For Example, " Dhoni is a cool captain" Cool is his nature it is his Function. He is always cool even the Team is in underpressure. So cool is his Natural Function. And, We dont know how he is so cool in under...

What is UUID ? and Where its used ?

This article is regarding UUID and where it is used. The UUID is generated using a cryptographically strong pseudo random number generator. It is belongs to the package java.util. It is used to generate random number which is stronger and there wont be any  repetition of number.  UUID can be used for Creating random file names, Maintaining different Session id in web application. Transaction id in Banking sector. Primary key in Database. public static void man(String[] args) { UUID uniqueId = UUID . randomUUID ( ) ; System . out . println ( "The unique id is" + uniqueId . toString ( ) ) ; }