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...

HOW TO ENABLE COPY PASTE IN CMD – WINDOWS

HOW TO ENABLE COPY PASTE IN CMD – WINDOWS By Default Windows do not allow users to Copy text and Paste it in Command prompt Or Copy text from Command prompt and paste it elsewhere. But there is an option in CMD itself to enable Copy & Paste Text in Windows Command Prompt. Today in this tutorial we will learn how to  Enable Copying and Pasting Texts in Windows Command prompt . One of the main advantage of this will be that you can copy any command that you find on the internet or from any word/excel file and paste it directly in CMD and execute that command just like that. Step 1:  Open CMD, Just type CMD in search or Press Win + X key to select Command Prompt. Step 2:  Right Click on the Title of the CMD window and Select Properties just like its shown in the below Picture Step 3:  You will see a Pop up Window coming up, Now on the Right hand side, Under  Edit Options , Just Check  Quick Edit Mode  and click  OK ...