• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubts in mock exam ques

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everybody,
These are the few ques from various mock exams in which I've got doubts .I'll be thankful if anyone can help me with these ques
Q1.Which of the following would be a valid inner class for this class?
Select all valid answers.
a) class B {
}
b) class B extends A {
}
c) class B {
B() {
System.out.println("i = " + i);
}
}
d) class B {
class A {
}
}
e) class A {
}
ans given is a&c.But I think b is also correct.
Q2.
Which statement is true about a non-static inner class?
A.It must implement an interface.
B.It is accessible from any other class. //why is this option wrong?
C.It can only be instantiated in the enclosing//ans
class.
D.It must be final if it is declared in a method
scope.
E.It can access private instance variables in the
enclosing object. //ans
Q3.
for(int i=0; i<N; i++)>
String tmp = "test"; //why this loop shows compilation error as variable redeclaration

Q4.Why '\u000A' is invalid expr while '\uBABE' is valid?
Q5.
. Which of the following places no constraints on the type of elements, order of elements, or repetition of elements with in the collection.?
A) Collection
B) collection//ans given
C) Map
D) Set
Do we have anything as collection?
Q6.
import java.io.*;
public class TestIPApp {
public static void main(String args[]) {
RandomAccessFile file = new RandomAccessFile("test.txt", "rw");
file.writeBoolean(true);
file.writeInt(123456);
file.writeInt(7890);
file.writeLong(1000000);
file.writeInt(777);
file.writeFloat(.0001f);
file.seek(5);
System.out.println(file.readInt());
file.close();
}
}
Select correct answer:
A) 123456
B) 7890 //ans
C) 1000000
D) .0001
Can anyone explain why is this option correct?
Thanks in advance,
Mamta
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q1 i think part of the question is missing
Q2 i think is worded wrong should say directly accessible
Q3 entire code not posted
Q4 i dont know the answer
Q5 doesnt make sense to me
Q6seek
public void seek(long pos)
throws IOException
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs. The offset may be set beyond the end of the file. Setting the offset beyond the end of the file does not change the file length. The file length will change only by writing after the offset has been set beyond the end of the file.
Parameters:
pos - the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
Throws:
IOException - if pos is less than 0 or if an I/O error occurs.
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my answer got cut off
Q6 the boolian is byte0, the first int takes up 4 bytes so it will read the second int
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As to question 4,I think because \u000a represents \n character in Java,so '\u000a' can be seen as '\n',which is not a valid statement.similarily,'\u000d'='\r'.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic