Posts

String Concept

public static void main(String[] args) {      boolean stmt1 = "champ" == "champ";      boolean stmt2 = new String("champ").equals(new String("champ"));       boolean stmt3 = "champ".toString()=="champ";     System.out.println(stmt1 && stmt2 && stmt3);  } The output is true

String Concept

public static void main(String[] args) { boolean stmt1 = "champ" == "champ"; boolean stmt2 = new String("champ") == "champ"; boolean stmt3 = new String("champ") == new String("champ"); System.out.println(stmt1 && stmt2 || stmt3); } The output is false

Java Constructor 2 !?

What is the expected output? class Plant {       Plant() {       System.out.println("Plant created"); } } class Tree extends Plant {        Tree() {        System.out.println("Tree created");        super(); } } public class Test { public static void main(String args[]) {        Tree tree = new Tree(); } } Please choose only one answer: 1)    Plant created        Tree created 2)    Tree created        Plant created 3)    RuntimeException 4)     Compilation error

Java Constructor !?

What is the expected output? public class Profile {           private Profile(int w) { // line 1           System.out.println(w); }            public static Profile() { // line 5            System.out.println(10); }            public static void main(String args[]) {            Profile obj = new Profile(50); } } Please choose only one answer: Won't compile because of line (1) – constructor can't be private 10            50 50 Won't compile because of line (5) – constructor can't be static

Java Constructor Legal Modifiers.

Q.What are the legal modifiers which the constructor can be declared with? Please choose all the answers that apply: public protected private final static abstract

String and NULL!!!

What is the expected output?       public static void main(String args []) {                     String stmt = null;                     System.out.print(null+stmt);                     System.out.print(stmt+null);         } Please choose only one answer:  RuntimeException is thrown because of the first print statement  RuntimeException is thrown because of the second print statement  nullnullnullnull  nullnull  compilation error Post your doubt in the comment section below.

String and StringBuffer!

Select the common methods, which are defined for both type String and type StringBuffer ?         Please choose all the answers that apply:   toString()   length()  append(String)  trim()  equals(Object)   Put your doubts in the comment section.