My Report

Java Programming Practice Test 3


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following Java program?

 
    class output 
    {
        public static void main(String args[])
        { 
           String s1 = "Hello";
           String s2 = s1.replace('l','w');
           System.out.println(s2);
        }
    }

2. Which of these method of Object class can clone an object?

3. At line number 2 in the following code, choose 3 valid data-type attributes/qualifiers among "final, static, native, public, private, abstract, protected"

public interface Status
   {
        /* insert qualifier here */ int MY_VALUE = 10;
   }

4. Which of these is correct way of inheriting class A by class B?

5. What will be the output of the following Java code?

 
    class output 
    {
        public static void main(String args[])
        {
            String a = "hello i love java";
            System.out.println(a.indexOf('i')+" "+a.indexOf('o') +" "+a.lastIndexOf('i')+" "+a.lastIndexOf('o'));
        }
    }

6. What will be the output of the following Java program?

    class String_demo 
    {
        public static void main(String args[])
        {
            char chars[] = {'a', 'b', 'c'};
            String s = new String(chars);
            System.out.println(s);
        }
   }

7. What will be the output of the following Java program?

    class Output 
    {
        static void main(String args[]) 
        {    
             int x , y = 1;
             x = 10;
             if(x != 10 && x / 0 == 0)
                 System.out.println(y);
             else
                 System.out.println(++y);
        } 
    }

8. What will be the output of the following Java snippet, if attempted to compile and run this code with command line argument "java abc Rakesh Sharma"?

public class abc
{
	int a=2000;
        public static void main(String argv[])
        {
	    System.out.println(argv[1]+" :-Please pay Rs."+a);
        }
}

9. Which of these method of class String is used to remove leading and trailing whitespaces?

10. What will be the output of the following Java code?

 
public class Boxer1 
{
    Integer i;
    int x;
   public Boxer1(int y) 
   {
        x = i+y;
        System.out.println(x);
   }
   public static void main(String[] args) 
   {
       new Boxer1 (new Integer(4));
   }
}

 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.