• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Some sample questions...

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, all,
Here are some sample questions. Please take a look at them, and provide the answers. I have done them, just want to verify the answer some other ranchers. Thanks.

Q-2
Sample Code
String readString() {
char buf[] = new char[80];
Reader in = new InputStreamReader(System.in);
in.read(buf, 0, 80);
return new String(buf);
}
What is wrong with method readString()?
Choice 1
all IO methods must be declared public
Choice 2
an InputStreamReader object can not be bound to standard input
Choice 3
logic to catch exceptions for the InputStream statements is missing
Choice 4
String objects can not be instantiated with a character array
Choice 5
you can not cast InputStreamReader into Reader
Q-3
class A {
int i, j, k;
public A() { i=3; }
public A(int i1) { i = i1; }
public A(int i1, int k1) {
this(i1);
k = k1;
}
}


What is wrong with class A?
Choice 1
there are multiple methods named A()
Choice 2
nothing
Choice 3
a method can not have the same name as its class
Choice 4
all methods must declare return datatypes
Choice 5
methods can not invoke other methods in their own class

Q-4
for(int i=0;i<22;i++) {
if(i<10) {
int j= 2 + i;
}
System.out.println("i: " + i + " j: " + j);
}


What is wrong with the above code?
Choice 1
you can not declare integer i inside the for-loop declaration
Choice 2
variable j is referenced outside its scope
Choice 3
you can not declare variables inside a for-loop
Choice 4
you can not print integer values without converting them to strings
Choice 5
the syntax of the "if" statement is incorrect
Q-5
for(int i=0;i<22;i++) {
if(i<10) {
int j= 2 + i;
}
System.out.println("i: " + i + " j: " + j);
}


What is wrong with the above code?
Choice 1
you can not declare integer i inside the for-loop declaration
Choice 2
variable j is referenced outside its scope
Choice 3
you can not declare variables inside a for-loop
Choice 4
you can not print integer values without converting them to strings
Choice 5
the syntax of the "if" statement is incorrect
Q-6
If memory may be running low, what could free some up?
Choice 1
invoke System.garbageCollection()
Choice 2
reduce the priority of less important threads
Choice 3
invoke System.gc()
Choice 4
make more methods synchronized
Choice 5
call destroy() on any objects you no longer need

 
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
the serial order of the Q's was wrong.
Anyway
Q2-
missing logic i.e. try,catch statements as in.read() throws IOException
Q3-
Nothing wrong with code simply constructors r overloaded.
Q4 & Q5-
j is out of scope
Q6-
System.gc(),but no guarentee when it will run.
Hope i am right,let me know.
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic