Core Java 1

20 Questions | Attempts: 268
Please wait...
Question 1 / 21
🏆 Rank #--
Score 0/100

1. What will be the output of the program? class Test {     public static void main(String [] args)     {         int x=20;         String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge";         System.out.println(sup);     } }

Submit
Please wait...
About This Quiz
Core Java 1 - Quiz

This questions are about the core java concepts includeing language fundamentals, objects,interfaces,threads,loops,collections and garbage collections. . .

2.

What first name or nickname would you like us to use?

You may optionally provide this to label your report, leaderboard, or certificate.

2. Which three guarantee that a thread will leave the running state?
  1. yield()
  2. wait()
  3. notify()
  4. notifyAll()
  5. sleep(1000)
  6. aLiveThread.join()
  7. Thread.killThread()

Submit

3. What will be the output of the program?
public class X 
{ 
    public static void main(String [] args) 
    {
        try 
        {
            badMethod();  
            System.out.print("A"); 
        }  
        catch (Exception ex) 
        {
            System.out.print("B"); 
        }  
        finally 
        {
            System.out.print("C"); 
        }  
        System.out.print("D"); 
    }  
    public static void badMethod() {} 
} 

Submit

4. Public void test(int x) {     int odd = 1;     if(odd) /* Line 4 */     {         System.out.println("odd");     }     else     {         System.out.println("even");     } } Which statement is true?

Submit

5.
try 
{ 
    int x = 0; 
    int y = 5 / x; 
} 
catch (Exception e) 
{
    System.out.println("Exception"); 
} 
catch (ArithmeticException ae) 
{
    System.out.println(" Arithmetic Exception"); 
} 
System.out.println("finished");
  State True or False: The output of the above code is the below Exception finished

Submit

6. Suppose that you would like to create an instance of a new Map that has an iteration order that is the same as the iteration order of an existing instance of a Map. Which concrete implementation of the Map interface should be used for the new instance?

Submit

7. Which four options describe the correct default values for array elements of the types indicated?
  1. int -> 0
  2. String -> "null"
  3. Dog -> null
  4. char -> '\u0000'
  5. float -> 0.0f
  6. boolean -> true

Submit

8. Class X implements Runnable {     public static void main(String args[])     {         /* Missing code? */     }     public void run() {} } Which of the following line of code is suitable to start a thread ?

Submit

9. What will be the output of the program? class Bitwise {     public static void main(String [] args)     {         int x = 11 & 9;         int y = x ^ 3;         System.out.println( y | 12 );     } }

Submit

10. Which of the following would compile without error?

Submit

11. Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO (first-in, first-out) sequence?

Submit

12. State the below statement is not false about static nested class:  It's variables and methods must be static

Submit

13. Which three are valid declarations of a char?
  1. char c1 = 064770;
  2. char c2 = 'face';
  3. char c3 = 0xbeef;
  4. char c4 = \u0022;
  5. char c5 = '\iface';
  6. char c6 = '\uface';

Submit

14. Public class X {     public static void main(String [] args)     {         X x = new X();         X x2 = m1(x); /* Line 6 */         X x4 = new X();         x2 = x4; /* Line 8 */         doComplexStuff();     }     static X m1(X mx)     {         mx = new X();         return mx;     } } After line 8 runs. how many objects are eligible for garbage collection?

Submit

15.
What is the output for the below code ?

	
public class A {
       public A() {
        System.out.println("A");
}
}

	
public class B extends A implements Serializable {
       public B() {
        System.out.println("B");
    }

	
}

	
public class Test {
       
       public static void main(String... args) throws Exception {
              B b = new B();
       
        ObjectOutputStream save = new ObjectOutputStream(new FileOutputStream("datafile"));
        save.writeObject(b); 
        save.flush(); 
        

	
        ObjectInputStream restore = new ObjectInputStream(new FileInputStream("datafile"));
        B z = (B) restore.readObject();

	
        

	
       }
       
}

Submit

16. Public class Runner {                 public static void main(String args[])                 {                     System.out.println("This is a correct program");                     continue;                 } } State True or False: The above program prints a output

Submit

17. /* Missing Statement ? */ public class foo {     public static void main(String[]args)throws Exception     {         java.io.PrintWriter out = new java.io.PrintWriter();         new java.io.OutputStreamWriter(System.out,true);         out.println("Hello");     } } What line of code should replace the missing statement to make this program compile?

Submit

18. Public class Outer {     public void someOuterMethod()     {         //Line 5     }     public class Inner { }         public static void main(String[] argv)     {         Outer ot = new Outer();         //Line 10     } }
Which of the following code fragments inserted, will allow to compile?

Submit

19. Which cause a compiler error? (choose all that apply)

Submit

20. Which of the following are Java reserved words?

Submit
×
Saved
Thank you for your feedback!
View My Results
Cancel
  • All
    All (20)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What will be the output of the program?...
Which three guarantee that a thread will leave the running state?...
What will be the output of the program?...
Public void test(int x)...
Try ...
Suppose that you would like to create an instance of a new Map that...
Which four options describe the correct default values for array...
Class X implements Runnable...
What will be the output of the program?...
Which of the following would compile without error?
Which collection class allows you to associate its elements with key...
State the below statement is not false about static nested class:...
Which three are valid declarations of a char?...
Public class X...
What is the output for the below code ?...
Public class Runner...
/* Missing Statement ? */...
Public class Outer...
Which cause a compiler error? (choose all that apply)
Which of the following are Java reserved words?
play-Mute sad happy unanswered_answer up-hover down-hover success oval cancel Check box square blue
Alert!