This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Lara Technology 9:30 AM – 1:30 PM Lara Technology
1. Program 1. public class A { 2. 3. private static int counter = 0; 4. 5. public static int getInstanceCount() { 6. return counter; 7. } 8. 9. public A() { 10. ++counter; 11. } 12. 13. } Given this code from Class B: 25.A a1 =new A(); 26. A a2 =new A(); 27. A a3 =new A();
28. System.out.printIn(A.getInstanceCount() ); What is the result? A. Compilation of class A fails. B. Line 28 prints the value 3 to System.out. C. Line 28 prints the value 1 to System.out. D. A runtime error occurs when line 25 executes. E. Compilation fails because of an error on line 28. Ans:: B2.Program Given: 10. class Foo {
11. static void alpha() { /* more code here */ } 12. void beta() { /* more code here */ } 13. } Which two are true? (Choose two.) A. Foo.beta () is a valid invocation of beta (). B. Foo.alpha () is a valid invocation of alpha (). C. Method beta () can directly call method alpha (). D. Method alpha () can directly call method beta (). 3.Program Which Man class properly represents the
relationship “Man is a best Friend who is a Dog”? A. class Man extends Dog { } B. class Man implements Dog { } C. class Man { private BestFriend dog; } D. class Man { private Dog bestFriend; } E. class Man { private Dog<bestFriend> } F. class Man { private BestFriend<dog> } Ans::A
11. public One foo() { return this; } 12. } 13. class Two extends One { 14. public One foo() { return this; } 15. } 16. class Three extends Two { 17. // insert method here 18. } Which three methods, inserted individually, correctly complete the Three class? (Choose two.) A. public void foo() { } B. public Two foo() { return this; }
C. public One foo() { return this; } D. public Object foo() { return this; } E. public Three foo() { return this; } Ans:: B,c,e5.Program
Given:
10. class One { 11. public One() { System.out.print(1); } 12. } 13. class Two extends One { 14. public Two(int i) { System.out.print(2); } 15. } 16. class Three extends Two {
17. public Three() {super(5); System.out.print(3); } 18. } 19. public class Numbers{ 20. public static void main( String[] args) { new Three(); } 21. } What is the result when this code is executed?
A. 1 B. 3 C. 123 D. 321 E. The code rims with no output.
Ans::C
6.Program 11. class Person { 12. String name = “No name’; 13. public Person(String nm) { name = nm; } 14. } 15. 16. class Employee extends Person { 17. String emplD = “0000”; 18. public Employee(String id) {super(“manu”) ; this.empID = id; } 19. } 20.
21. public class EmployeeTest { 22. public static void main(String[] args) { 23. Employee e = new Employee(”4321”); 24. System.out.println(e.empID); 25. } 26. } What is the result? A. 4321 B. 0000 C. An exception is thrown at runtime. D. Compilation fails because of an error in line 18. Ans::A
7.Program
Given:
1. class SuperClass { 2. public A getA() { 3. return new A(); 4. } 5. } 6. class SubClass extends SuperClass { 7. public B getA() { 8. return new B(); 9. } 10. } Which is true? A. Compilation will succeed if A extends B. B. Compilation will succeed if B extends A.
C. Compilation will always fail because of an error in line 7. D. Compilation will always fail because of an error in line 8. Ans::A8.Program 11. class Cup { } 12. class PoisonCup extends Cup { } 21. public void takeCup(Cup c) { 22. if(c instanceof PoisonCup) { 23. System.out.println(”Inconceivable!”); 24. } else if(c instanceof Cup) {
25. System.out.println(”Dizzying intellect!”); 26. } else { 27. System.exit(0); 28. } 29. } And the execution of the statements: Cup cup = new Cup(); takeCup(cup); What is the output? A. Inconceivable! B. Dizzying intellect! C. The code runs with no output. D. An exception is thrown at runtime.
E. Compilation fails because of an error in line 22. Ans::B9.Program1. class TestA { 2. public void start() { System.out.println(”TestA”); } 3. } 4. public class TestB extends TestA { 5. public void start() { System.out.println(”TestB”); } 6. public static void main(String[] args) { 7. ((TestA)new TestB()).start(); 8. } 9. }
What is the result? A. TestA B. TestB C. Compilation fails. D. An exception is thrown at runtime. Ans::B10.Program11. class Alpha{12. public void foo(){System.out.println(“Afoo”);}13.}14. public class Beta extends Alpha{15. public void foo(){System.out.println(“Bfoo”);}16. public static void main (String args[]){
C.methods and constructors D.none of the above Ans:: methods
69.While Installing JDK,Which Softwares are mandatory?A.Edit plusu B.PublicJRE C.Windows XP D.Development tools Ans:: D
70.Is it possible to have more than one reference to the same object? Ans:: s71.Primitives are pass by value.true/false? Ans:: true72.In a Single package Is it possible to keep a
two main method?True/FalseAns:: true
73. In a empty class,How many members will be there?
A.3 B.1 C.2 D.0Ans:: 1
74. private methods are similar to as?A.non-final methods B.final methods C.Default methods D.none of the above Ans:: final methods75.for interface we can’t create object?True/false.Ans:: S76..By using temporary variable we are avoiding class cast
exception?True/FalseAns:: False77. Cyclic calling is happening in………A. methods B. constructors C. methods and constructors D.none of the above Ans:: methods 78.Is it possible to keep abstract constructor in a class? Ans:: no79.What is the default value for String?A.null B.abc C.String D.None Ans:: null80.In which access level we can use outside the package?
A.Private B.Public C.Protected D.Default Ans:: pubic and protected
81. Which method can’t inherit sub class?
A.protected B.public C.default D.none of the above