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. What will be the output of the following Java program?

 
    class output 
    {
        public static void main(String args[])
        {
           String s1 = "Hello World";
           String s2 = s1.substring(0 , 4);
           System.out.println(s2);
        }
   }

3. Which of these method of class String is used to extract more than one character at a time a String object?

4. What will be the output of the following Java snippet, if attempted to compile and execute?

class abc
{
    public static void main(String args[])
    {
        if(args.length>0)
        System.out.println(args.length);
    }
}

5. Which annotation is used to represent command line input and assigned to correct data type?

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

 
    class output 
    {
        public static void main(String args[])
        { 
           String s1 = "Hello";
           String s2 = new String(s1);
           String s3 = "HELLO";
           System.out.println(s1.equals(s2) + " " + s2.equals(s3));
        }
    }

7. Which of these is an incorrect statement?

8. What is the use of @syntax?

9. What will be the output of the following Java program, Command line exceution is done as - "java Output This is a command Line"?

    class Output 
    {
        public static void main(String args[]) 
        {
            System.out.print(args[3]);
        }
    }

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

    class box 
    {
        int width;
        int height;
        int length;
        int volume;
        void volume(int height, int length, int width) 
        {
             volume = width * height * length;
        } 
    }    
    class Prameterized_method{
        public static void main(String args[]) 
        {
            box obj = new box();
            obj.height = 1;
            obj.length = 5;
            obj.width = 5;
            obj.volume(3, 2, 1);
            System.out.println(obj.volume);        
        } 
    }

 

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.