Answe
Answe
E
ACE
D
AD
A
A
D
AC
BD
A
D
C
BC
ABC
C
B
AC
C
B
D
C
B
F
AB
E
AC
AC
A
AD
CEF
BE
A
BE
A
A
A
D
A
B
E
AC
D
B
B
A
C
A
C
A
C
C
C
C
B
A
A
ABC
B
C
C
D
A
B
A
D
D
A
E
D
D
AC
D
A
A
E
ABE
C
BE
ADF
B
(But, 12 is
missing)
B
B
E
A
A
E
C
C
?
AB
A
CE
?
B
E
A
A
A
A
BC
C
B
BCE
E
A
ABC
E
C
C
C
C
A
BD
CE
B
AD
C
C
C
C
CD
A
C
C
ABD
A
A
E
C
B
C
A
B
D
C
CD
C
AD
A
A
A
C
B
C
A
C
E
D
C
B
E
C
D
C
E
C
D
D
C
D
C
C
B
A
Only I and III
A
B
C
C
B
ADE
?
C
B
B
D
C
C
D
A
D
C
C
C
C
CD
D
C
BD
B
C&D-?
BD
AE
BD
B
C
C
A
B
B
D
B
AD
CD
A
A
C
D
C
E
C
C
Document
shows it as G
E
A
A
B
B
A
A
A
C
AC
ABF
E
B
DGH
D
10:10
exception
output: ABCC
Output:
c=
b = false
f = 0.0
Output:
Java
Jeve
va
Output:
Super
Sub
Sub
Output:
Super
Sub
Sub
Shining Sun
Shining Sun
Found Default
}
}
catch (Exception e) {
System.out.println("invalid index");
}
System.out.println(sum);
}
}
Output:
invalid index
12
public class Test1 {
public static void main (String args[]) {
boolean log3 = (5.0 != 6.0) && (4 != 5);
boolean log4 = (4!=4) || (4==4);
System.out.println("log3:"+log3+"\nlog4:"+log4);
}
}
Output:
log3:true
log4:true
Output:
Result:30
class A {
public A(){
System.out.print("A");
}
}
class B extends A {
public B(){
System.out.print("B");
}
}
}
Output: ABC
}
}
}
Output: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at Test1.main(Test1.java:15)
C)
public class Test1 {
public static void main (String args[]) {
String[][] arra = new String[3][];
arra[0]=new String[]{"rose", "lily"};
arra[1]=new String[]{"apple","berry","cherry","grapes"};
arra[0]=new String[]{"beans","carrot","potato"};
for (String a[]:arra[][]){
for (String x:a[]){
toUpperCase();
}
}
}
}
Output:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token(s), misplaced construct(s)
Can only iterate over an array or an instance of java.lang.Iterable
Syntax error on token "[", Expression expected after this token
The method toUpperCase() is undefined for the type Test1
at Test1.main(Test1.java:17)
D)
Output:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Can only iterate over an array or an instance of java.lang.Iterable
Type mismatch: cannot convert from element type String[] to String
Cannot invoke toUppercase() on the array type String[]
at Test1.main(Test1.java:21)
public void m2(){
System.out.println("Green");
}
}
Output:
Yellow
Pink
Red
DBConfiguration dbconf = r.configureDB("manager","manager");
}
}
Output:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
DBConfiguration cannot be resolved to a variable
at Test1.configureDB(Test1.java:10)
at Test1.main(Test1.java:15)
C)
class DBConfiguration {
String user;
String password;
}
}
public static void main (String args[]){
Test1 r = new Test1();
DBConfiguration dbconf = r.configureDB("manager","manager");
}
}
Output:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token "new", delete this token
DBConfiguration cannot be resolved to a variable
at Test1.configureDB(Test1.java:10)
at Test1.main(Test1.java:15)
Syntax error in while loop statement
public class Test1 {
static void dispResult(int[] num){
try {
System.out.println(num[1]/(num[1]-num[2]));
} catch (ArithmeticException e){
System.err.println("first exception");
}
System.out.println("Done");
}
Java Test1 1 2
Output: 1525
question is how many objects created - 1 or 2? i thnk answer is 1, bcz only one "new instance" available. Obj2 also point to obj
at Test1.main(Test1.java:11)
import java.util.ArrayList;
public class Test1 {
public static void main (String[] args) {
ArrayList<String> list = new ArrayList<>();
list.add("SE");
list.add("EE");
list.add("ME");
list.add("SE");
list.add("EE");
list.remove("SE");
System.out.println("Values are:"+ list);
}
}
Output:
Values are:[EE, ME, SE, EE]
5:5
Option D is in correct bcz variable i is not declared/inialized
option E is incorrect bcz int is missing in statement i=0;
import java.util.ArrayList;
public class Test1 {
public static void main (String[] args) {
ArrayList myList= new ArrayList(1);
String[] myArray;
try{
while(true){
myList.add("MyString");
}
} catch (RuntimeException re) {
System.out.println("Runtime exception");
} catch (Exception e) {
System.out.println("Caught an exception");
}
System.out.println("Ready to use");
}
}
Output:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2245)
at java.util.Arrays.copyOf(Arrays.java:2219)
at java.util.ArrayList.grow(ArrayList.java:242)
at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:216)
at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:208)
at java.util.ArrayList.add(ArrayList.java:440)
at Test1.main(Test1.java:8)
String[] d = {"a","b","c"};
update(d);
for (String s : d){
System.out.println(s+" ");
}
}
}
Output:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method update(String[]) from the type Test1 refers to the missing type List
at Test1.main(Test1.java:14)
Option B:
Output:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at Test1.main(Test1.java:12)
Option C:
Output:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method update(String[]) from the type Test1 refers to the missing type List
at Test1.main(Test1.java:14)
Option D:
Output:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at Test1.main(Test1.java:12)
Option E:
output:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method update(String[]) is undefined for the type Test1
at Test1.main(Test1.java:14)
public class Test2 {
int x;
int y;
public void doStuff(int x, int y){
this.x = x;
y=this.y;
}
public void display(){
System.out.print(x+" " + y + ": ");
}
}
}
Output:
square
circle
...
public class Test1 {
public static void main (String[] args) {
StringBuilder sb1 = new StringBuilder("Duke");
String str1 = sb1.toString();
String str2 = str1; //If we insert Option A - Line 10 will print - true
//String str2 = new String(str1);//If we insert Option B - Line 10 will print - false
//String str2 = sb1.toString(); //If we insert Option C - Line 10 will print - false
//String str2 = "Duke"; //If we insert Option D - Line 10 will print - false
System.out.println(str1 == str2);
}
}
Output: Unscuccessful
class Caller {
private void init(){
System.out.println("Iniatialized");
}
public void start(){
init();
System.out.println("Started");
}
}
public class Test2 {
public static void main (String args[]){
Caller c = new Caller();
c.start();
c.init();
}
}
Output:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method init() from the type Caller is not visible
at Test2.main(Test2.java:14)
import java.util.ArrayList;
import java.util.List;
public class Test1 {
public static void main (String[] args) {
List<Integer> list = new ArrayList<>();
list.add(21); list.add(13);
list.add(30); list.add(11);
list.add(2);
list.removeIf(e -> e%2 = 0);
System.out.println(list);
}
}
Output: 15 30 75 60 90
class Test1 {
static int i = 7;
public static void main (String args[]){
Test1 obj = new Test1();
obj.i++;
Test1.i++;
obj.i++;
System.out.print(Test1.i+" "+obj.i);
}
}
Output: 10 10
class Tours{
public static void main(String[] args){
System.out.print("Happy Journey! "+args[1]);
}
}
at Test1.main(Test1.java:8)
BD ? - Saravana
import java.util.ArrayList;
import java.util.List;
public class Test1 {
public static void main(String[] args){
List<String> names = new ArrayList<>();
names.add("Robb");
names.add("Bran");
names.add("Rick");
names.add("Bran");
if (names.remove("Bran")){
names.remove("Jon");
}
System.out.println(names);
}
}
Output: [Robb, Rick, Bran]
C? - Saravana
Interface has default method which should have method body
}
System.out.println(number);
}
}
Output:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
number cannot be resolved to a variable
at Test1.main(Test1.java:8)
at Test1.main(Test1.java:6)
public class Test1 {
public static void main (String args[]) {
int[] xx=null;
for (int ii : xx){
System.out.println(ii);
}
}
}
Output:
Exception in thread "main" java.lang.NullPointerException
at Test1.main(Test1.java:4)
class MyString {
String msg;
MyString(String msg){
this.msg=msg;
}
}
public class Test1 {
public static void main (String args[]) {
System.out.println("Hello "+ new StringBuilder("StringBuilder Java SE 8"));
System.out.println("Hello "+ new MyString("Java SE 8"));
}
}
Output:
Hello StringBuilder Java SE 8
Hello MyString@fb53f6
public class Test1 {
public static void main (String args[]) {
System.out.println( 28 + 5 <= 4 + 29 );
System.out.println( (28 + 5) <= (4 + 29) );
}
}
output:
true
true
bool[0]=new Boolean(Boolean.parseBoolean("true"));
bool[1]=new Boolean(null);
System.out.println(bool[0]+" "+bool[1]);
}
}
output:
true false
E?
at Test1.main(Test1.java:7)
B? - Saravana
AD - Saravana ?
C is not correct as class Z does noit implement abstract methodY which is from interface
D is correct as if the subclass is abstract, then sub class is no need to implement abstract methods from adstract class &
interface
E - Saravana ?
System.out.println(planets.length);
System.out.println(planets[1].length());
}
}
output:
4
5
import java.awt.List;
import java.util.ArrayList;
public class Test1 {
public static void main(String[] args){
List colors = new ArrayList();
colors.add("green");
colors.add("red");
colors.add("blue");
colors.add("yellow");
colors.remove(2);
colors.add(3, "cyan");
System.out.println(colors);
}
}
output:
[green, red, yellow, cyan]
C - Saravana?
interface Z {
}
if u see options after the statement - what is the result , it's option C.
class Vehicle {
String type = "4W";
int maxSpeed = 100;
Vehicle (String type, int maxSpeed){
this.type = type;
this.maxSpeed = maxSpeed;
}
}
public class Test2 extends Vehicle {
String trans;
Test2 (String trans){
this.trans = trans;
}
Test2 (String type, int maxSpeed, String trans){
super(type, maxSpeed);
this(trans);
}
public static void main(String[] args){
Test2 c1 = new Test2("Auto");
Test2 c2 = new Test2("4W", 150, "Manual");
System.out.println(c1.type+" "+c1.maxSpeed+" "+c1.trans);
System.out.println(c2.type+" "+c2.maxSpeed+" "+c2.trans);
}
}
Output:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Implicit super constructor Vehicle() is undefined. Must explicitly invoke another constructor
Constructor call must be the first statement in a constructor
at Test2.<init>(Test2.java:11)
at Test2.main(Test2.java:19)
public class Test2 {
public static int main(String[] args){
String[] s = new String[1];
s[0] = "Sathes";
s[1] = "kumar";
System.out.println(s[1]);
return 0;
}
}
Output:
Error: Main method must return a value of type void in class Test2, please
define the main method as:
public static void main(String[] args)
at Test2.main(Test2.java:4)
public class Test2 {
public static void main(String[] args){
StringBuilder sb = new StringBuilder(5);
String s = "";
if (sb.equals(s)){
System.out.println("Match 1");
} else if (sb.toString().equals(s.toString())){
System.out.println("Match 2");
} else {
System.out.println("No match");
}
}
}
output: Match 2
}
Output:
one
class A {
public A(){
System.out.print("A");
}
}
class B extends A {
public B(){
super();
System.out.print("B");
}
}
}
Output: ABC
tried both B & C - both got exception
not sure - have to run once in command line
1 or 2?
none of the option compiles, all giving error. If we match return type of data (List) with
return type of method Update, then option C is correct
have to run this in command line with Javac & Java
D ah ?
Option C/G - partially correct
Given options has no exact output
See explanation
String myStr = str;
This above assignment is out of scope after try block.
I think it's A
Correct declaration:
public class Test2 {
public static void main(String[] args){
Object array[];
Boolean array1[] = new Boolean[3];
int[] array3;
Float[] array4 = new Float[4];
}
}
A A A
E E E
A, C, E A, C, E A, C, E
D D D
A, D A, D A, D
A A A A
A A A
D D D D
A, C A, C A,C A, C
B, D B, D B, D
A A C A(10, 8, 6, 4, 2, 0)
D D D D int f = ps.index(p2)
C C C C
A, B A,B A, B
ns = 50; s = 125
ns = 125; s = 125
B B B B ns = 0; s = 100
D D D caught: java.lang.RunTime Exception (only as doPrint() will throw the exception
C C C Ternary operation (x>10 ? ">" : x<10 ? "<" : "=")
B B B null will get printed when no assignment is made to the array (Null Unix Linux So
java
jeve
D B C va
E E E
A, C A,C A, C
D D D D Compilation fails only at n3. Runtime exception is not required to be handled
B B B Failure
B B B
A A A Stringbuilder.insert()
C D C C false false (isEmpty prints false when there is a space inside)
E E E
C C C C
A A A
C D C
C C C C Planets[2] will print the reference of array in index 2
C C C 123xxx
C C C
B B B
A A A A var + Hello World! (10 Hello World)
D A A
A, b A,B,C ABC
B B B
C C C
C C C Java byte code can run on any platform that has JRE
D B D int can be used as reference type for arrays
A A A
A A A
B B B B
A A A A
D D D
D D D
A A A
A B E Orange compilation fails
D D D
D D D D
A, C A, C A,D AC PASS NEW()
D D D Compile error will be shown only at the usage not at declaration
D A A
A A A
E E E
A, B A, B ABE
C C C
B
(But, 12 is
A, B A missing) 12, Invalid Index
B B B
B B B
E E E
A A A
A A A
E E E
C C C
C C C C
A A A
A, B A,B AB
A A A
C, E C, E C,E CE
B B B
B A B While loop syntax is incorrect
B B E
B B B
A A A A
A A A
A A A
E A A A Only A.java file compiles successfully (B.java contains private variable inside met
Encapsulation -
Allows a class implementation to change without
changing the clients
Protects confidential data from leaking out of objects
A, D, F A,B,D ABD Enables class implementaion to protect its variants
A A A
A A A A How many marklist instances are created? 1
C C E Compilation error - variable sum might not have been initialized
C C C C
B B B
A C C no argument class Z initializes varibable X3 (since the instanct is created for that
A A A
B B B B
B D D Number format exception while parsing(808.1)
A D C
C, D C,D CD
C C C C
A A,D AD protected variables are also considered as encapsulated
A A A A Toy calculation - abstract calculation method
A A A A remove from list (removes only one occurrence)
B A A 011 - count resets to 0
D C C use .delete to empty all contents of Stringbuilder
B B B
C C C
B B A 1.0, 1 (float variable)
x: 0 y: 0
B B C x: 3 y: 4
D E E E check spelling of ArrayLIst in option E
D D D
C C C
B B B
Compilation fails since the number variable is
C C E declared inside the try block
C C C
D D D
B B B
E E E C Compilation fails while multiplying number and assigning to a string
C E
C C
B D
D D
E C C C false true (variable can be declared at the end)
D D
C C
C C
B B
A A
E Only I and III
A A A A it accesses private method
B B
D C Null 0.0
C C C C myStr: 7007, myNum:9009
D B
A, D, E ADE
B ?
D C
D B Lions is always jumping; it's a static variable which is intialized once the main me
A B a,e o,o
D D D D double d = 203.22; float f = d; compilation error occurs
C C
C C
B D 10, 20, 30, 10, 20, 30
A A
D D
C C
C C
B C key is used outside of the loop
Out of limits
D C hEllO jAvA
A, D CD
C D 12345 printed 6 times
A C -5
B, D BD
B B
planets.length - 4
B B B C & D - ? planets[0].lengh - 5
B, C, D BD double and float; int can't be pointed to float calculation
A, E AE
B, D BD
B B
B C
C C C C A, B, D, E (while 'B' - break;)
A A A A green, red, yellow, cyan
B B B B At line 7, insert --x;
int sum is 30
B B B B double sum is 30.0
C D D D Null pointer will be thrown while printing an empty/null string
Replace in string replaces all characters
F B Hi XvXryonx!;
public static void main
A, D A, D A,D AD static public void main
Readbook, Setbook
change n3 to abstract class
C, D C, D D CD insert method declaration in n4
A A
A A
C C
D D
B C
E E E E Invalid Ternary operation. Compilation fails
C C
C C
Documen
t shows it
G as G
C B NegativeArraySizeException
num[0][0] = 10
num[0][1] = 10
A A A A num[0][2] = 10
B B
B B B B Code compiles but does not execute
A A
A A
B, D A javac Main.java
C C C C A work done
A, C AC
A, B, F ABF
B E Concat can't be used on Stringbuilder
D B Match 2
acct.amount = 0
acct.changeamount(-acct.amount)
D, F, G D, G, H D,G,H DGH acct.changeamount(-acct.getamount)
B D Compilation fails. Method signature can't be same
() will throw the exception first and exception will move to catch block
o that only certain fields and methods of an object are accessible from other objects
t required to be handled
declaration
ough the value doesn't contain decimal point
private variable inside method and C.java doesn't contain matching class name - which are not allowed)
dard for loop
C,D
C
A,D
A
A
A
C
B
C
B
B
E
D
C
B
C
C
D
B
C
E
C
D
D
C
D
C
C
B
A
Only III
A
B
D
C
B
B,C,F
B
D
C
A
B
B
D
A,D
D
A
B
D,G,H