Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

New Java

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 8

5B2A7D64

1) Given following piece of code:


public class School{
public abstract double numberOfStudent{};
}
http://www.examveda.com/given-the-following-piece-of-code-java-programming-on-
interfaces-and-abstract-class-1/
d)Class School must be defined abstract.

2) Given following piece of code:


public interface guard{
void doYourJob();
public abstract class Dog implements Guard{};
}
http://www.examveda.com/given-the-following-piece-of-code-java-programming-on-
interfaces-and-abstract-class-8/
D. This code will compile without any errors.

3) public class MyProgram


{
public static void throwit{}
{
throw new RuntimeException();
}
Public static void main (String args[])
{
try
{
System.out.println("Hello World");
throwit{};
System.out.println("done");
}
finally{
System.out.println("Finally executing");
}}
}
http://www.indiabix.com/java-programming/exceptions/011001
D. The program will print Hello world, then will print Finally executing, then
will print that a RuntimeException has occurred.

4)what is the output of this program?


class exception_handling{
}
static void throwexception{}throws ArithmeticException{
}
System.out.println("0");
throw new ArithmeticException{"Exception"};
}
Public static void main (String args[])
{
try
{
throwexception{};
}
catch(ArithmeticException e){
System.out.println("A");
}
}
}
http://www.sanfoundry.com/java-mcqs-finally-built-in-exceptions/
ans 0A

5)what is the output of this program if input given is 'abcqfghqbcd'


class Input_output{
char c;
Bufferedreader obj=new BufferedReader(new inputStreamReader(System.input)}
do{
c=(char)obj.read{};
System.out.print(c);
}while(c!='q');
}
http://www.sanfoundry.com/java-mcqs-input-output-basics/
ans abcq

6) which of the following statement are incorrect?


a)static methods can call other static methods only.
b)static methods must only access static data.
c)static methods can not refer to ths or super in any way.
d)when object of class is decelerd,each object contains its awn copy of staic
http://www.sanfoundry.com/java-mcqs-arrays-revisited-static/
ans d

7)what is the output of this program?


class Output{
Public static void main (String args[]){
Integer i=new Integer(257);
byte x=i.byteValue();
System.out.print(x);
}
}
http://www.sanfoundry.com/java-mcqs-java-lang-integer-long-charcter-wrappers/
ans 1;

8)which of the following is incorrect statement about packages?


a)Interface specifies what class must do but not how it does.
b)Interface are specified public if they are to be accessed by any code in the
programme.
c)All variables in interface are implicitly final and static.
d)All variables are static and methods are public if interface is defined public.
ans
http://www.sanfoundry.com/java-mcqs-interfaces/
d)

9)class X
{
public static void main(String[] args)
{
int x=9;
if(x==9){
int x=8;
System.out.println(X);
}
}}
http://www.sanfoundry.com/java-mcqs-class-fundamental-declaring-objects/
ans compilation error

10) Which of the following statements are incorrect?


a) public members of class can be accessed by any code in the program.
b) private members of class can only be accessed by other members of the class.
c) private members of class can be inherited by a sub class, and become protected
members in sub class.
d) protected members of a class can be inherited by a sub class, and become private
members of the sub class.
Answer: c
http://www.sanfoundry.com/java-mcqs-access-control/
Explanation: private members of a class can not be inherited by a sub class

11).
Which statement is true?
A. Memory is reclaimed by calling Runtime.gc().
B. Objects are not collected if they are accessible from live threads.
C. An OutOfMemory error is only thrown if a single block of memory cannot be
found that is large enough for a particular requirement.
D. Objects that have finalize() methods always have their finalize() methods
called before the program ends.
http://www.indiabix.com/java-programming/garbage-collections/021001
Answer: Option B

12)
what is the output of this program?
class static_out{
static int x;
static int y;
void add(int a,int b){
x=a+b;
y=x+b;
}
}
class static_use{
public static void main(String[] args)
{
staic_out obj1=new static_out();
staic_out obj2=new static_out();
int a=2;
obj1.add(a,a+1);
obj2.add(5,a);
System.out.println(obj1.x+""+obj2.y)
}

}
ans 79
http://www.techepi.com/online-test/java/low2/high/.html
http://www.studytonight.com/java/tests/12

1. What is the stored in the object obj in following lines of code?


box obj;
a) Memory address of allocated memory of object.
b) NULL
c) Any arbitrary pointer
d) Garbage
View Answer
http://www.sanfoundry.com/java-mcqs-class-fundamental-declaring-objects/
Answer: b

given following piece of code:


public class School{
public abstract double numberOfStudent();
}

15 )class Boo
{
Boo(String s) { }
Boo() { }
}
class Bar extends Boo
{
Bar() { }
Bar(String s) {super(s);}
void zoo()
{
// insert code here
}
}

A. Boo f = new Boo(24) { };


B. Boo f = new Bar() { }; @
http://www.indiabix.com/java-programming/inner-classes/
ans b

public class ExceptionTest


{
class TestException extends Exception {}
public void runTest() throws TestException {}
public void test() /* Point X */
{
runTest();
}
}
At Point X on line 5, which code is necessary to make the code compile?
[A]. No code is necessary.
[B]. throws Exception @
[C]. catch ( Exception e )
[D]. throws RuntimeException
http://www.indiabix.com/java-programming/exceptions/discussion-117
ans b

6. What is synchronization in reference to a thread?


a) Its a process of handling situations when two or more threads need access to a
shared resource.
b) Its a process by which many thread are able to access same shared resource
simultaneously.
c) Its a process by which a method is able to access many different threads
simultaneously.
d) Its a method that allow to many threads to access any information require.
View Answer
http://www.sanfoundry.com/java-mcqs-isalive-join-thread-synchronization/
Answer: a

)What is the output of this program?

class newthread extends Thread {


newthread() {
super("My Thread");
start();
}
public void run() {
System.out.println(this);
}
}
class multithreaded_programing {
public static void main(String args[]) {
new newthread();
}

a) My Thread
b) Thread[My Thread,5,main]
c) Compilation Error
d) Runtime Error
View Answer
http://www.sanfoundry.com/java-mcqs-isalive-join-thread-synchronization/
Answer: b

) What is the output of this program?

class string_class {
public static void main(String args[])
{
String obj = "hello";
String obj1 = "world";
String obj2 = obj;
obj2 = " world";
System.out.println(obj + " " + obj2);
}
}
advertisements
a) hello hello
b) world world
c) hello world
d) world hello
View Answer
http://www.sanfoundry.com/java-mcqs-string-class/
Answer: c

what is the output of this programme?

import java.io.*;
class streams {
public static void main(String[] args) {
try {
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeFloat(3.5);
oos.flush();
oos.close();
}
catch(Exception e) {
System.out.println("Serialization" + e);
System.exit(0);
}
try {
float x;
FileInputStream fis = new FileInputStream("serial");
ObjectInputStream ois = new ObjectInputStream(fis);
x=ois.readInt();
ois.close();
System.out.println(x);
}
catch (Exception e) {
System.out.print("deserialization");
System.exit(0);
}
}
}
ans New input stream is linked to streal serials, an object ois of
ObjectInputStream is used to access this newly created stream, ois.close(); closes
the stream hence we cant access the stream and ois.available() returns 0.
Output:
javac streams.java
java streams
0

)What is the output of the programme

class multithreaded_programing{
public static void main(String args[]){
new newthread();
}}
class newthread implements Runnable {
Thread t;
newthread() {
t1 = new Thread(this,"Thread_1");
t2 = new Thread(this,"Thread_2");
t1.start();
t2.start();
}
public void run() {
t2.setPriority(Thread.MAX_PRIORITY);
System.out.print(t1.equals(t2));
}
}
class multithreaded_programing {
public static void main(String args[]) {
new newthread();
}
}
a) true
b) false
c) truetrue
d) falsefalse
View Answer
http://www.sanfoundry.com/java-mcqs-creating-threads/
Answer: d
Explanation: Threads t1 & t2 are created by class newthread that is implementing
runnable interface,
hence both the threads are provided their own run() method specifying the actions
to be taken.
When constructor of newthread class is called first the run() method of t1
executes than the run method of t2 printing 2 times
false as both the threads are not equal one is having different priority than
other, hence falsefalse is printed.
Output:
$ javac multithreaded_programing.java
$ java multithreaded_programing
falsefalse

You might also like