Labels

.NET Job Questions About Java Absract class Abstract class Abstract Class and Interface Aggregation ajax aop apache ofbiz Apache ofbiz tutrial Association authentication autocad basics batch Binary Tree bootstrap loader in java build Builder design pattern C++ Job Questions caching CallableStatement in java certifications Chain of responsibility Design pattern charts check parentheses in a string Classes classloader in java classloading concept code quality collage level java program Composition concurrency Concurrency Tutorial Converting InputStream to String Core Java core java concept core java interview questions Core Java Interview Questions Core Java Questions core java tutorial CyclicBarrier in Java data structures database Database Job Questions datetime in c# DB Db2 SQL Replication deserialization in java Design Patterns designpatterns Downloads dtd Eclipse ejb example/sample code exception handling in core java file handling injava File I/O vs Memory-Mapped Filter first program in spring flex Garbage Collection Generics concept in java grails groovy and grails Guice Heap hibernate Hibernate Interview Questions how-to IBM DB2 IBM DB2 Tutorial ide immutable Interceptor Interface interview Interview Questions for Advanced JAVA investment bank j2ee java JAVA Code Examples Java 7 java changes java class loading JAVA Classes and Objects Java Classloader concept Java classloading concept java cloning concept java collection Java collection interview questions Java Collections java concurrency Java CountDownLatch java definiton Java design pattern Java EE 5 Java EE 6 Java Exceptions Java file Java Garbage Collection Java generics Java Glossary java hot concept java immutable concept Java Interface Java interview Question java interview question 2012 java interview question answer Java Interview Questions Java Interview Questions and Answers java interview topic java investment bank Java Job Questions java multithreading java multithreading concept java new features Java Packages java proxy object java questions Java Serialization Java serialization concept java serialization interview question java session concept java string Java Swings Questions java synchronization java threading Java Threads Questions java tutorial java util; java collections; java questions java volatile java volatile interview question Java Wrapper Classes java.java1.5 java.lang.ClassCastException JavaNotes javascript JAX-WS jdbc JDBC JDBC Database connection jdk 1.5 features JDK 1.5 new features Concurrent HashMap JMS interview question JMS tutorial job JSESSIONID concept JSESSIONID interview Question JSF jsp JSP Interview Question JSP taglib JSTL with JSP Junit Junit Concept Junit interview question.Best Practices to write JUnit test cases in Java JVM Linux - Unix tutorial Marker Interfaces MD5 encryption and decryption messaging MNC software java interview question musix NCR java interview question Networking Job Questions news Object Serialization Objects ojdbc14.jar OOP Oracle Oracle SQL Query for two timestamp difference orm own JavaScript function call in Apache ofbiz Packages Palm Apps patterns pdf persistence Portal Portlet Spring Integration Prime number test in java programs Rails Reboot remote computers REST Ruby Sample application schema SCJP security Senior java developer interviews servlet3 servlets session tracking singleton design pattern Spring Spring 2.5 Framework spring ebook Spring framework concept spring MVC spring pdf Spring Security Spring Security interview questions SQL SQL performance SQL Query to create xml file Sql Query tuning ssis and ssrs StAX and XML string concept string immutable string in java strings struts Struts2 Struts2 integration synchronization works in java Technical Interview testing tips Tomcat top Tutorial Volatile in deep Volatile working concept web Web Developer Job Questions web services weblogic Weblogic Application Server websphere what is JSESSIONID xml XML parsing in java XML with Java xslt


Saturday, 6 July 2013

SCJP Questions 131-140


                                    PREVIOUS                       NEXT

Question 131
Click the Exhibit button.
1. class Computation extends Thread {
2.
3. private int num;
4. private boolean isComplete;
5. private int result;
6.
7. public Computation(int num) { this.num = num; }
8.
9. public synchronized void run() {
10. result = num * 2;
11. isComplete = true;
12. notify();
13. }
14.
15. public synchronized int getResult() {
16. while (!isComplete) {
17. try {
18. wait();
19. } catch (InterruptedException e) { }
20. }
21. return result;
22. }
23.
24. public static void main(String[] args) {
25. Computation[] computations = new Computation [4];
26. for (int i = 0; i < computations.length; i++) {
27. computations[i] = new Computation(i);
28. computations[i] .start();
29. }
30. for (Computation c : computations)
31. System.out.print(c.getResult() +“ “);
32. }
33. }
What is the result?
A. The code will deadlock.
B. The code may run with no output.
C. An exception is thrown at runtime.
D. The code may run with output “0 6”.
E. The code may run with output “2 0 6 4’.
F. The code may ruin with output “0 2 4 6”.
Answer: F

Question 132
Given:
7. void waitForSignal() {
8. Object obj = new Object();
9. synchronized (Thread.currentThread()) {
10. obj.wait();
11. obj.notify();;
12. }
13. }
Which is true?
A. This code may throw an InterruptedException.
B. This code may throw an IllegalStateException.
C. This code may throw a TimeoutException after ten minutes.
D. This code will not compile unless “obj.wait()” is replaced with
“((Thread) obj).wait()”.
E. Reversing the order of obj.wait() and obj.notify() may cause this
method to complete normally.
F. A call to notify() or notifyAll() from another thread may cause this
method to complete normally.
Answer: B

Question 133
Given:
foo and bar are public references available to many other threads. foo
refers to a Thread and bar is an Object. The thread foo is currently
executing bar.wait(). From another thread, which statement is the
most reliable way to ensue that foo will stop executing wait()?
A. foo.notify();
B. bar.notify();
C. foo.notifyAll();
D. Thread.notify();
E. bar.notiFYAll();
F. Object.notify();
Answer: E

Question 134
Which two are true? (Choose two.)
A. An encapsulated, public class promotes re-use.
B. Classes that share the same interface are always tightly
encapsulated.
C. An encapsulated class allows subclasses to overload methods, but
does NOT allow overriding methods.
D. An encapsulated class allows a programmer to change an
implementation without affecting outside code.
Answer: AD

Question 135
Given:
1. package test;
2.
3. class Target {
4. public String name = “hello”;
5. }
What can directly access and change the value of the variable name?
A. any class
B. only the Target class
C. any class in the test package
D. any class that extends Target
Answer: C

Question 136
Given:
1. public class Target {
2. private int i = 0;
3. public int addOne() {
4. return ++i;
5. }
6. }
And:
1. public class Client {
2. public static void main(String[] args) {
3. System.out.println(new Target().addOne());
4. }
5. }
Which change can you make to Target without affecting Client?
A. Line 4 of class Target can be changed to return i++;
B. Line 2 of class Target can be changed to private int i = 1;
C. Line 3 of class Target can be changed to private int addOne() {
D. Line 2 of class Target can be changed to private Integer i = 0;
Answer: D

Question 137
Given:
1. package geometry;
2. public class Hypotenuse {
3. public InnerTriangle it = new InnerTriangle();
4. class InnerTriangle {
5. public int base;
6. public int height;
7. }
8. }
Which is true about the class of an object that can reference the
variable base?
A. It can be any class.
B. No class has access to base.
C. The class must belong to the geometry package.
D. The class must be a subclass of the class Hypotenuse.
Answer: C

Question 138
Given:
11. class ClassA {}
12. class ClassB extends ClassA {}
13. class ClassC extends ClassA {}
and:
21. ClassA p0 = new ClassA();
22. ClassB p1 = new ClassB();
23. ClassC p2 = new ClassC();
24. ClassA p3 = new ClassB();
25. ClassA p4 = new ClassC();
Which three are valid? (Choose three.)
A. p0 = p1;
B. p1 =p2;
C. p2 = p4;
D. p2 = (ClassC)p1;
E. p1 = (ClassB)p3;
F. p2 = (ClassC)p4;
Answer: AEF

Question 139
Given:
11. class Animal { public String noise() { return “peep”; } }
12. class Dog extends Animal {
13. public String noise() { return “bark”; }
14. }
15. class Cat extends Animal {
16. public String noise() { return “meow”; }
17. }
.....
30. Animal animal = new Dog();
31. Cat cat = (Cat)animal;
32. System.out.printIn(cat.noise());
What is the result?
A. peep
B. bark
C. meow
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: E

Question 140
Given:
11. abstract class Vehicle { public int speed() { return 0; } }
12. class Car extends Vehicle { public int speed() { return 60; } }
13. class RaceCar extends Car { public int speed() { return 150; }}
......
21. RaceCar racer = new RaceCar();
22. Car car = new RaceCar();
23. Vehicle vehicle = new RaceCar();
24. System.out.println(racer.speed() + “, ‘ + car.speed()
25. + “, “+ vehicle.speed());
What is the result?
A. 0, 0,0
B. 150, 60, 0
C. Compilation fails.
D. 150, 150, 150
E. An exception is thrown at runtime.
Answer: D

                                    PREVIOUS                       NEXT

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...