Java Basic interview Questions

Some interview questions.

1. What is the value of bellow code:

int a=5;
int b=2;

float c= a/b;

System.out.println(c);

2. What is the difference between default and protected access modifier?

3. What is the output of bellow code?

class X{
int a=10;

}

class Y extends X{
int a =90;

public static void main(String[] args){
X x = new Y();
System.out.println(x.a);
}
}


4. What is Runtime Polymorphism?

5. What is the output of below code?

class X{
public String test()
{
return "From X.test()";
}

}

class Y extends X{
public String test()
{
return From Y.test();
}

public static void main(String[] args){
X x = new Y();
System.out.println(x.test);
}
}


6. What will be the output f below code?

class X{
public String test()
{
return "From X.test()";
}

}

class Y extends X{
public String test()
{
return From Y.test();
}

public String notOverridedMethod(){
return "From notOverridedMethod()";
}

public static void main(String[] args){
X x = new Y();
System.out.println(x.notOverridedMethod());
}
}
Reactions

Post a Comment

0 Comments