Find the given file.
package com.concretepage;
public class A extends B {
public static void main(String[] args) {
Short myNum = 7;
System.out.println(add(myNum, 6));
}
}
class B {
int add(int x, int y) { return x + y; }
}
What is the result?
Correct Answer:
Compilation fails due to an error on line 5
Note: This Question is unanswered, help us to find answer for this one
What is the output for the below code?
public class A {
int add(int i, int j){
return i+j;
}
}
public class B extends A{
public static void main(String argv[]){
short s = 9;
System.out.println(add(s,6));
}
}
Correct Answer:
Compile fail due to error on line no 9
Note: This Question is unanswered, help us to find answer for this one
class A {
A(String s) {
}
A() {
}
}
1. class B extends A {
2. B() { }
3. B(String s) {
4. super(s);
5. }
6. void test() {
7. // insert code here
8. }
9. }
Which of the below code can be insert at line 7 to make clean
compilation?
Correct Answer:
A a = new B();
Note: This Question is unanswered, help us to find answer for this one
What is the output for the below code ?
public class A {
int k;
boolean istrue;
static int p;
public void printValue() {
System.out.print(k);
System.out.print(istrue);
System.out.print(p);
}
}
public class Test{
public static void main(String argv[]){
A a = new A();
a.printValue();
}
}
Correct Answer:
0 false 0
Note: This Question is unanswered, help us to find answer for this one
Find the given file.
package com.concretepage;
public class Computer implements Device{
public void doIt() { }
}
abstract class Phone1 extends Computer { }
abstract class Phone2 extends Computer{
public void doIt(int x) { }
}
class Phone3 extends Computer implements Device{
public void doStuff() { }
}
interface Device {
public void doIt();
}
What is the result?
Correct Answer:
Compilation succeeds
Note: This Question is unanswered, help us to find answer for this one
Correct Answer:
GetCust
Note: This Question is unanswered, help us to find answer for this one
What will be the result of compiling the following code:
public class SuperClass {
public int doIt(String str, Integer… data)throws Exception{
String signature = “(String, Integer[])”;
System.out.println(str + ” ” + signature);
return 1;
}
}
public class SubClass extends SuperClass{
public int doIt(String str, Integer… data)
{
String signature = “(String, Integer[])”;
System.out.println(“Overridden: ” + str + ” ” +
signature);
return 0;
}
public static void main(String… args)
{
SuperClass sb = new SubClass();
sb.doIt(“hello”, 3);
}
}
Correct Answer:
Complilation fails
Note: This Question is unanswered, help us to find answer for this one
What is the output for the below code?
public class Test {
public static void main(String[] args){
String value = “abc”;
changeValue(value);
System.out.println(value);
}
public static void changeValue(String a){
a = “xyz”;
}
}
Correct Answer:
abc
Note: This Question is unanswered, help us to find answer for this one
ou have two class files name Test.class and Test1.class inside javaproject directory.
Test.java source code is:
public class Test{
public static void main (String[] args){
System.out.println(“Hello Test”);
}
}
Test1.java source code is :
public class Test1{
public static void main (String[] args){
System.out.println(“Hello Test1″);
}
}
you have issued below commands from command prompt.
cd javaproject
java Test Test1
What is the output?
Correct Answer:
Hello Test
Note: This Question is unanswered, help us to find answer for this one
Find the given file.
package com.concretepage;
class Road {
public static void main(String[] args) {
for(int __x = 0; __x < 3; __x++) ;
int #lb = 7;
long [] x [5];
Boolean []ba[];
}
enum Traffic { RED, YELLOW, GREEN };
}
What is the result?
Correct Answer:
Compilation fails with an error on line 5
Note: This Question is unanswered, help us to find answer for this one
What is the output for the below code?
public class A {
static{System.out.println(“static”);}
{ System.out.println(“block”);}
public A(){
System.out.println(“A”);
}
public static void main(String[] args){
A a = new A();
}
}
Correct Answer:
A block static
Note: This Question is unanswered, help us to find answer for this one
What is the output for the below code?
interface A {
public void printValue();
}
1. public class Test{
2. public static void main (String[] args){
3. A a1 = new A() {
4. public void printValue(){
5. System.out.println(“A”);
6. }
7. };
8. a1.printValue();
9. }
10. }
Correct Answer:
A
Note: This Question is unanswered, help us to find answer for this one
Find the given file.
package com.concretepage;
enum Day {
MON("1"), TUE("2"), WED("3");
String s;
Day(String s) { this.s = s; }
}
public class Test {
static Day d;
public static void main(String[] args) {
System.out.println(d.MON.s + " " + d.TUE.s);
}
}
What is the result?
Correct Answer:
1 2
Note: This Question is unanswered, help us to find answer for this one
What is the output for the below code?
public class A {
public void printName(){
System.out.println(“Value-A”);
}
}
public class B extends A{
public void printName(){
System.out.println(“Name-B”);
}
}
public class C extends A{
public void printName(){
System.out.println(“Name-C”);
}
}
1. public class Test{
2. public static void main (String[] args) {
3. B b = new B();
4. C c = new C();
5. b = c;
6. newPrint(b);
7. }
8. public static void newPrint(A a){
9. a.printName();
10. }
11. }
Correct Answer:
Compilation fails due to an error on lines 5
Note: This Question is unanswered, help us to find answer for this one
Choose the correct statement.
Correct Answer:
"A extends B" is correct if A and B are either both classes or both interfaces
Note: This Question is unanswered, help us to find answer for this one
Find the given file.
package com.concretepage;
public class Test {
public enum Days { MON, TUE, WED, THU };
public static void main(String[] args) {
for(Days d : Days.values() );
Days [] d2 = Days.values();
System.out.println(d2[3]);
}
}
What is the result?
Correct Answer:
THU
Note: This Question is unanswered, help us to find answer for this one
What is the output for the below code?
public class A {
int i = 10;
public void printValue() {
System.out.println(“Value-A”);
}
}
public class B extends A{
int i = 12;
public void printValue() {
System.out.print(“Value-B”);
}
}
public class Test{
public static void main(String argv[]){
A a = new B();
a.printValue();
System.out.println(a.i);
}
}
Correct Answer:
Value-B 10
Note: This Question is unanswered, help us to find answer for this one
try{
File f = new File(“a.txt”);
}catch(Exception e){
}catch(IOException io){
}
Is this code create new file name a.txt?
Correct Answer:
Compilation Error
Note: This Question is unanswered, help us to find answer for this one
What is the output for the below code?
1. public class Test {
2. public static void main(String[] args){
3. byte b = 6;
4. b+=8;
5. System.out.println(b);
6. b = b+7;
7. System.out.println(b);
8. }
9. }
Correct Answer:
Compilation fails with an error at line 6
Note: This Question is unanswered, help us to find answer for this one
What is the output for the below code?
public class C {
}
public class D extends C{
}
public class A {
public C getOBJ(){
System.out.println(“class A – return C”);
return new C();
}
}
public class B extends A{
public D getOBJ(){
System.out.println(“class B – return D”);
return new D();
}
}
public class Test {
public static void main(String… args) {
A a = new B();
a.getOBJ();
}
}
Correct Answer:
class B – return D
Note: This Question is unanswered, help us to find answer for this one