What is the output for following code
final class Complex {
private final double re;
private final double im;
public Complex(double re, double im) {
this.re = re;
this.im = im;
}
public String toString() {
return "(" + re + " + " + im + "i)";
}
}
public class sample1 {
public s tatic void main(String args[]){
Complex c = new Complex(10, 15);
System.out.println("Complex number is " + c);
}
}
What is the output for following code
final class Complex {
private final double re;
private final double im;
public Complex(double re, double im) {
this.re = re;
this.im = im;
}
public String toString() {
return "(" + re + " + " + im + "i)";
}
}
public class sample1 {
public s tatic void main(String args[]){
Complex c = new Complex(10, 15);
System.out.println("Complex number is " + c);
}
}
Predict the output of following program. Note that fun() is public in base and private in derived.
class Base {
public void foo() { System.out.println("Base"); }
}
class Derived extends Base {
private void foo() { System.out.println("Derived"); }
}
public class sample1 {
public static void main(String args[]){
Base b = new Derived();;
b.show();
}
}
Predict the output of following program. Note that fun() is public in base and private in derived.
class Base {
public void foo() { System.out.println("Base"); }
}
class Derived extends Base {
private void foo() { System.out.println("Derived"); }
}
public class sample1 {
public static void main(String args[]){
Base b = new Derived();;
b.show();
}
}
Which of these keywords is used to refer to member of base class from a subclass?
Which of these keywords is used to refer to member of base class from a subclass?
Which method of java is invoked by JVM to reclaim the inaccessible memory location
Which method of java is invoked by JVM to reclaim the inaccessible memory location
What is the output for following code
class Base{
public Base(){
System.out.print(" Base ");
}
}
public class sample1 extends Base{
public sample1(){
this(" Examveda ");
System.out.print(" Derived ");
}
public sample1(String s){
System.out.print(s);
}
public static void main(String args[]) {
new sample1();
}
}
What is the output for following code
class Base{
public Base(){
System.out.print(" Base ");
}
}
public class sample1 extends Base{
public sample1(){
this(" Examveda ");
System.out.print(" Derived ");
}
public sample1(String s){
System.out.print(s);
}
public static void main(String args[]) {
new sample1();
}
}
What is the output for following code
class Base {
public void show() {
System.out.println("Base::show() called");
}
}
class Derived extends Base {
public void show() {
System.out.println("Derived::show() called");
}
}
public class sample1 {
public static void main(String args[])
{
Base b = new Derived();;
b.show();
}
}
What is the output for following code
class Base {
public void show() {
System.out.println("Base::show() called");
}
}
class Derived extends Base {
public void show() {
System.out.println("Derived::show() called");
}
}
public class sample1 {
public static void main(String args[])
{
Base b = new Derived();;
b.show();
}
}
Which of the following is true about inheritance in Java?
1) Private methods are final.
2) Protected members are accessible within a package and
inherited classes outside the package.
3) Protected methods are final.
4) We cannot override private methods.
Which of the following is true about inheritance in Java?
1) Private methods are final.
2) Protected members are accessible within a package and
inherited classes outside the package.
3) Protected methods are final.
4) We cannot override private methods.
A class member declared protected becomes member of subclass of which type
A class member declared protected becomes member of subclass of which type
What is the result of compiling and running this program?
class Mammal{
void eat(Mammal m){
System.out.println("Mammal eats food");
}
}
class Cattle extends Mammal{
void eat(Cattle c){
System.out.println("Cattle eats hay");
}
}
class Horse extends Cattle{
void eat(Horse h){
System.out.println("Horse eats hay");
}
}
public class sample1 extends Base{
public static void main(String args[])
{
Mammal h = new Horse();
Cattle c = new Horse();
c.eat(h);
}
}
What is the result of compiling and running this program?
class Mammal{
void eat(Mammal m){
System.out.println("Mammal eats food");
}
}
class Cattle extends Mammal{
void eat(Cattle c){
System.out.println("Cattle eats hay");
}
}
class Horse extends Cattle{
void eat(Horse h){
System.out.println("Horse eats hay");
}
}
public class sample1 extends Base{
public static void main(String args[])
{
Mammal h = new Horse();
Cattle c = new Horse();
c.eat(h);
}
}
What is the output for following code
class Grandparent {
public void Print() {
System.out.println("Grandparent's Print()");
}
}
class Parent extends Grandparent {
public void Print() {
System.out.println("Parent's Print()");
}
}
class Child extends Parent {
public void Print() {
super.super.Print();
System.out.println("Child's Print()");
}
}
public class Main {
public static void main(String[] args) {
}
}
public class sample1 {
public static void main(String args[])
{
Child c = new Child();
c.Print();
}
}
What is the output for following code
class Grandparent {
public void Print() {
System.out.println("Grandparent's Print()");
}
}
class Parent extends Grandparent {
public void Print() {
System.out.println("Parent's Print()");
}
}
class Child extends Parent {
public void Print() {
super.super.Print();
System.out.println("Child's Print()");
}
}
public class Main {
public static void main(String[] args) {
}
}
public class sample1 {
public static void main(String args[])
{
Child c = new Child();
c.Print();
}
}
Which method can’t be overridden?
Which method can’t be overridden?
What is the output for following code
class Base {
public void Print() {
System.out.println("Base");
}
}
class Derived extends Base {
public void Print() {
System.out.println("Derived");
}
}
public class sample1 {
public static void DoPrint( Base o ) {
o.Print();
}
public static void main(String args[])
{
Base x = new Base();
Base y = new Derived();
Derived z = new Derived();
DoPrint(x);
DoPrint(y);
DoPrint(z);
}
}
What is the output for following code
class Base {
public void Print() {
System.out.println("Base");
}
}
class Derived extends Base {
public void Print() {
System.out.println("Derived");
}
}
public class sample1 {
public static void DoPrint( Base o ) {
o.Print();
}
public static void main(String args[])
{
Base x = new Base();
Base y = new Derived();
Derived z = new Derived();
DoPrint(x);
DoPrint(y);
DoPrint(z);
}
}
What is the output for following code
class Base {
public static void show() {
System.out.println("Base::show() called");
}
}
class Derived extends Base {
public static void show() {
System.out.println("Derived::show() called");
}
}
class Main {
public static void main(String[] args) {
Base b = new Derived();;
b.show();
}
}
What is the output for following code
class Base {
public static void show() {
System.out.println("Base::show() called");
}
}
class Derived extends Base {
public static void show() {
System.out.println("Derived::show() called");
}
}
class Main {
public static void main(String[] args) {
Base b = new Derived();;
b.show();
}
}
The concept of multiple inheritance is implemented in Java by
I. Extending two or more classes.
II. Extending one class and implementing one or more interfaces.
III. Implementing two or more interfaces.
The concept of multiple inheritance is implemented in Java by
I. Extending two or more classes.
II. Extending one class and implementing one or more interfaces.
III. Implementing two or more interfaces.
What is the output for following code
class Base {
final public void show() {
System.out.println("Base::show() called");
}
}
class Derived extends Base {
public void show() {
System.out.println("Derived::show() called");
}
}
class Main {
public static void main(String[] args) {
Base b = new Derived();;
b.show();
}
}
What is the output for following code
class Base {
final public void show() {
System.out.println("Base::show() called");
}
}
class Derived extends Base {
public void show() {
System.out.println("Derived::show() called");
}
}
class Main {
public static void main(String[] args) {
Base b = new Derived();;
b.show();
}
}