Q1: What is the output of the following code (2) System

Object Oriented Programming 3rd Semester-SE Page 1 of 2 Q1: What is the output of the following code...

7 downloads 525 Views 22KB Size
Q1: What is the output of the following code String s=”welcome”; s.concat(“to java”); System.out.println(s);

(2)

Q2: If you want to find out where the position of the letter v in the string s containing “java”, which of the following could you use (2) a) mid(2,s); b) charAt(2); c) s.indexOf(‘v’); d) indexOf(s,’v’); Q3: Which of the following is correct? (2) a) String temp[]=new String {“j”,”a”,”z”}; b) String temp[]= {“j” ”a” ”z”}; c) String temp= {“j”,”a”,”z”}; d) String temp[]= {“j”,”a”,”z”}; Q4: Consider the following String S1 = “abc”; String S2 = “def”; String S3 = new String(S2); S2=S1; What is the value of S3 after the final line of the code is executed? Q5: Given the following class public class ZeroPoint { public static void main(String arg[ ] ){ int I = 0; //Here} } Which of the following line if placed after the comment //Here will not print out 0. System.out.println(I++); System.out.println(I+’0’); System.out.println(I); System.out.println(I--);

(2)

(2)

Q6: What String instance method would return true when invoked as follows? a.method(b); Where a equals “UETtaxila” and b equals “uetTAXILA”? equals() toLowerCase() toUpperCase() equalsIgnoreCase()

(2)

Q7:What is the output of the following StringBuffer sb1 = new StringBuffer("Amit"); StringBuffer sb2= new StringBuffer("Amit"); String ss1 = "Amit"; System.out.println(sb1==sb2); System.out.println(sb1.equals(sb2)); System.out.println(sb1.equals(ss1)); System.out.println("Poddar".substring(3));

(2)

(2)

Q8: What is the output of following if the return value is "the value 0 if the argument string is equal to this string; a value less than 0 if this string is lexicographically less than the string argument; and a value greater than 0 if this string is lexicographically greater than the string argument" (Assuming written inside main) String s5 = "AMIT"; String s6 = "amit"; System.out.println(s5.compareTo(s6)); System.out.println(s6.compareTo(s5)); System.out.println(s6.compareTo(s6)); Object Oriented Programming 3rd Semester-SE Page 1 of 2

Q9: What is the output (Assuming written inside main) String s1 = new String("amit"); String s2 = s1.replace('m','i'); s1.concat("Poddar"); System.out.println(s1); System.out.println((s1+s2).charAt(5));

(2)

Q10: What is the output (Assuming written inside main) String s1 = new String("amit"); System.out.println(s1.replace('m','r')); System.out.println(s1); String s3="arit"; String s4="arit"; String s2 = s1.replace('m','r'); System.out.println(s2==s3); System.out.println(s3==s4);

(2)

Q11: What is the output of following (Assuming written inside main) String s1 = "Amit"; String s2 = "Amit"; String s3 = new String("abcd"); String s4 = new String("abcd"); System.out.println(s1.equals(s2)); System.out.println((s1==s2)); System.out.println(s3.equals(s4)); System.out.println((s3==s4));

(2)

Q12: What will happen when you attempt to compile and run the following code

(2)

int Output=10; boolean b1 = false; if((b1==true) && ((Output+=10)==20)){ System.out.println("We are equal "+Output); }else { System.out.println("Not equal! "+Output); } Q13: Given the following variables

(2)

char c = 'c'; int i = 10; double d = 10; long l = 1; String s = "Hello"; Which of the following will compile without error?

(2)

1)c=c+i; 2)s+=i; 3)i+=s; 4)c+=s;

(14)

Q14: A stack stores data using first-in, last-out ordering. Stacks are controlled through two operations traditionally called push & pop. Make a class called Stack that implements a stack for integers and also a class TestStack demonstrates the Stack class. It create two integer stacks, push some value onto each and then pops them off.

Object Oriented Programming

3rd Semester-SE

Page 2 of 2