Oracle Certified Professional - Java SE 6 Programmer exam questions and answers
Abstract classes used when: Common abstract methods to be re-used for different clients. 'Extend' the class. Abstract classes do not have pre-defined methods, only abstract methods. T/F? False. Abstract class must have at least one abstract method, rest may be initiated pre-defined methods. Interfaces used when: All abstract methods and no pre-defined methods. 'Implement' the class. Local (method) variables must be defined but not initialized. T/F? False. Local variables must be initialized. Import karan. makes Import . redundant. T/F? False. Importing a class makes its methods and variables available, not its sub-class. s(s2) is same as s1==s2. T/F? False. s(s2) compares the content of the string whereas s1==s2 compares addresses. Groceries y = new Price(); Explain. Defining an interface of sub-class Price of super-class Groceries. Capacity of StringBuffer is __ more than no. of characters in it. 16 Object is stored in ____. Variable is stored in ____. Heap, Stack. What is Marker Interface? An interface that has no methods. Eg: Serializable, Clonable Constructors can only be overridden after inheriting. T/F? False. Constructors can not be overridden under any circumstance. Keyword: Finally Run a set of code after exception handling, whether the exception is thrown or not. Used for cleaning of resources. User can execute garbage collection at will. T/F? False. User can request garbage collection but it will occur when variable is de-referenced. JVM decides. Used for closing connections. Override the _____ method when garbage collection required. Finalize Keyword: Throw Single line statement executed explicitly. Throw is used to actually throw exception in Java. Keyword: Throws Used with a method. Used to declare exception possibly thrown by method. Interface can extend multiple interfaces. T/F? True. Class can implement multiple classes. T/F? False. Interfaces are 'implemented'. Class can implement multiple interfaces. Class can extend multiple classes. T/F? False. Java does not support multiple inheritance. Class can only extend one class. Interface can implement multiple interfaces. T/F? False. Only classes can implement. Class C { public static void main(String[] args) { int[]a1[]=new int[3][3]; //3 int a2[4]={3,4,5,6}; //4 int a2[5]; //5 }} What is the result of attempting to compile and run the program ?. letime error at lines 3,4,5 ltime error at line 4,5 letime error at line 3 4.Runtime Exception 5.None of the above 2. no value shoud be specified in the rightsidebrackets when constructing an array interface I{ void f1(); // 1 public void f2(); // 2 protected void f3(); // 3 private void f4(); // 4 } which lines generate compile time errors? letime error at lines 1,2,3,4 letime error at line 3 letime error at line 1 letime error at lines 3,4 5.None of the above 4 Explanation: all methods declared within an interface are implicitly public, a weaker access level can not be declared. class C{ int i; public static void main (String[] args) { int i; //1 private int a = 1; //2 protected int b = 1; //3 public int c = 1; //4 Sln(a+b+c); //5 }} letime error at lines 1,2,3,4,5 2 compiletime error at lines 2,3,4,5 letime error at lines 2,3,4 s 3 5.None of the above 2 Explanation: The access modifiers public, protected and private, can not be applied to variables declared inside methods. Accesss modifiers are to be used in front of instance level variables and instance level methods. class C { public static void main (String[] a1) { S(a1[1] + a1[2] + a1[3]); }} What is the result of attempting to compile and run the program? java command A B C 1.Prints: ABC 2.Prints BC and Runtime Exception 3.Prints: BCD 4.Runtime Exception 5.None of the above 2 Explanation: Array index starts from 0. array index outof bounds exception only till a1[2] is allowed. class C{ static int s; public static void main(String a[]){ C obj=new C(); obj.m1(); Sln(s); } void m1(); { int x=1; m2(x); Sln(x+""); } void m2(int x){ x=x*2; s=x; }} s 1,2 s 2,0 s 2,2 le time error 5.Noneofthe above 1 Explanation: Only objects and arrays are passed by are passed by value.s is a static variable which is global to the class.Class variables are declared static. class C { public static void main(String[] args) { int i1=1; switch(i1){ case 1: Sln("one"); case 2: Sln("two"); case 3: Sln("three"); }}} What is the result of attempting to compile and run the program? s one two three s one le time error 4.Runtime exceptionf 5.None of the above 1 Explanation: There is no break statement in case 1 so it causes the below case statements to execute regardless of their values
Written for
- Institution
- Oracle Certified Professional - Java SE 6 Programm
- Course
- Oracle Certified Professional - Java SE 6 Programm
Document information
- Uploaded on
- February 9, 2024
- Number of pages
- 31
- Written in
- 2023/2024
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
oracle certified professional java se 6