String literal questions on java and answer with solution


Objective type questions of string literals and answers in java programming


(1)

public class Literal {
    public static void main(String[] args) {
         String a="c:\\tc\\bin";
         System.out.println(a);
    }
}

What will output when you compile and run the above code?

(a) c:\\tc\\bin
(b) c:\tc\bin
(c) c:   c\bin
(d) Compiler error





Answer:  (b)

(2)

public class Literal {
    public static void main(String[] args) {
         String str="my id is :\12 and your";
         System.out.println(str);
    }
}

What will output when you compile and run the above code?

(a) my id is :\12 and your
(b) my id is :10 and your
(c) my id is :
    and your
(d) Compiler error





Answer: (c)

(3)

public class Literal {
    public static void main(String[] args) {
         String str="I know java\networking";
         System.out.println(str);
    }
}

What will output when you compile and run the above code?

(a) I know java\networking
(b) I know java
    etworking
(c) null
(d) Compiler error





Answer: (b)

(4)

public class Literal {
    public static void main(String[] args) {
         String str="I know java\c++";
         System.out.println(str);
    }
}

What will output when you compile and run the above code?

(a)I know java\c++
(b)I know java\c++\0
(c)“I know java\c++”
(d) Compiler error






Answer: (d)

(5)What will be output of following program?

class StringLiteral
{
   
    public static void main(String[] args)
    {  
         String str="india\0 usa";
         System.out.println(str);
    }
}

What will output when you compile and run the above code?

(a)India\0 usa
(b)india usa
(c)india
(d)Compiler error




1 comment:

iteducationcentre said...

Nice information. Thanks for sharing such an useful and helpful post.
Java course in Pune