• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

dought

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1:String s;
s = "Hello";
t = " " + "my";
s.append(t);// error(no append method for strings)
s.toLowerCase();
s+= " friend";
System.out.println(s);
What will be printed?
if i get a question like this ,eventhough we know that there is no append method for strings..& if the questiona aks for an ans what should we do
can anybody explain...if here was no append method the ans will be "hello friend"
2:Which comparisions are true for the following?
C x = new C(10L);
C y = new C(10L);
C z = y;
Long a = 10L;
int b = 10;
A:a == b
B:a == x
C:x == y
D:y == z
E:a == 10.0
ans:A,D,E
3:How can you implement encapsulation in a class?
A. Make all variables protected and only allow access via methods.
B. Make all variables private and only allow access via methods.
C. Ensure all variables are represented by wrapper classes.
D. Ensure all variables are accessed through methods in an ancestor
class.
ans:B
FilterInputStream is the parent class for BufferedInputStream and
> DataInputStream. Which classes are a valid argument for the constructor of a
> FilterInputStream?
>
> A. File
> B. BufferedInputStream
> C. OutputStream
> D. FileInputStream
> E. RandomAccessFile
ans:B,D
Which of the following statements are true?
A. For a given component, events will be processed in the order that
the listeners were added
B. Using the Adapter approach to event handling means creating blank
method bodies for all event methods
C. A component may have multiple listeners associated with it
D. Listeners may be removed once added
ans:B,C,D
anybody correct me if the ans are wrong
thanx
sherinn
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In 1. "t" has to be defined as String.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
2,3 4 & 5 seems to be correct
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sherin,
About (1): I guess ppl relate to this question with the famous s.append() question. I reckon, u have to assume that its ok.
about the rest, I agree with you,
-sampaths77
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
See this Question. I don't think the valid answers are A, D,E
only (y == z) return true.
2:Which comparisions are true for the following?
C x = new C(10L);
C y = new C(10L);
C z = y;
Long a = 10L;
int b = 10;
A:a == b
B:a == x
C:x == y
D:y == z // Only this return "True"
E:a == 10.0

To Test the above Question...I wrote the code
class C{
C(long l){}
}

class Test{
public static void main(String[]args){
C x = new C(10L);
C y = new C(10L);
C z = y;
Long a = 10L;
int b = 10;
System.out.println("a == b : "+ (a == b) );
System.out.println("a == x : "+ (a == x ));
System.out.println("x == y : "+ (x == y) );
System.out.println("y == z : "+ (y == z ));
System.out.println("a == 10.0 : " + (a == 10.0) );
}
When I executed I got the following o/p.
C:\Java\bin>javac Test.java
Test.java:23: Incompatible type for declaration. Can't convert long to java.lang.Long.
Long a = 10L;
^
Test.java:26: Incompatible type for java.lang.Long. Can't convert java.lang.Long to int.
System.out.println("a == b : "+ (a == b) );
^
Test.java:27: Incompatible type for java.lang.Long. Can't convert java.lang.Long to C.
System.out.println("a == x : "+ (a == x ));
^
Test.java:30: Incompatible type for java.lang.Long. Can't convert java.lang.Long to double.
System.out.println("a == 10.0 : " + (a == 10.0) );
^
4 errors
Do let me know if I am wrong.
Aruna
[This message has been edited by Aru (edited September 21, 2000).]
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In 1 .
It seems there will be 2 compile time errors.

I . t haven't initialized as String.
II. method append is not in the String class.
According to my knowledge the answer will be (If stated errors overcomes)

"Hello friend" not "hello friend".Because

s.toLowerCase();
has not assigned to the variable s.
i.e : s = s.toLowerCase();
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic