Java Question
abstract class A {
public void templateMethod() {
operation1 ();
operation3 ();
}
abstract public void operation1 ();
public void operation3() {
System.out.print("A-op3");
}
}
Class B extends A {
public void operation1() {
System.out.print("B-op1");
}
}
1.What is the output of:
B b1 = new B();
b1.operation1();
2.What is the output of:
A b1 = new B ();
a1.operation() ;
3.What is the output of :
A b1 = new B();
a1.templateMethod();
1)
Output:
___________________________________________________________________________________
2)
As given in question that object initiation with b1 and calling method with a1, by that it throws error (as a1 not found)
So, if u use b1 then output is
_______________________________________________________________________________________
3)
As given in question that object initiation with b1 and calling method with a1, by that it throws error (as a1 not found)
So, if u use b1 then output is
________________________________________________________________________________________
Java Question abstract class A { public void templateMethod() { operation1 (); operation3 (); } abstract...
This is a question about Java abstract classes. The correct answer is E and I do not understand why. Please be specific! I am a beginner in Java abstract classes and methods... 13.6 What is the output of running class Test? public class Test { public static void main(String[] args) { new Circle9(); } } public abstract class GeometricObject { protected GeometricObject() { System.out.print("A"); } protected GeometricObject(String color, boolean filled) { System.out.print("B"); } } public class Circle9 extends GeometricObject {...
abstract class Exp { abstract void print(); abstract int eval(); } class ConstExp extends Exp { private int value; ConstExp(int v) { value = v; } void print() { System.out.print(value); } int eval() { return value; } } class BinaryExp extends Exp { private Exp arg1; private Exp arg2; private char op; BinaryExp(char op, Exp arg1, Exp arg2) { this.op = op; this.arg1 = arg1; this.arg2 = arg2; } void print() { System.out.print("("); arg1.print(); System.out.print(" " + op + "...
What is wrong with the following Java Code. public class TestEdible { abstract class Animal { /** Return animal sound */ public abstract String sound(); } class Chicken extends Animal implements Edible { @Override public String howToEat() { return "Chicken: Fry it"; } @Override public String sound() { return "Chicken: cock-a-doodle-doo"; } } class Tiger extends Animal { @Override public String sound() { return "Tiger: RROOAARR"; } } abstract class Fruit implements Edible { // Data fields, constructors, and methods...
What is the Java output? Part One: class Driver { public static void main(String[] args) { int a = 5; int b = 3; if (a < b || a * 2 < b) System.out.print(a - b); System.out.print(b + a); } } Part Two: class Driver { public static void main(String[] args) { int a = 5; int b = 8; if (a < b) if (a * 2 < b) System.out.print("foo"); else System.out.print("bar"); else System.out.print("buz"); } }
All question base on Java Se 8 Consider the Top class i public abstract class Topí 2 private 3 protected String name; 4 public intx - 12; int age; e public Top(String name)[ this.namename age0; System.out.println(x); 10 12 public abstract void foo(String f); 13 Create a Middle class that extends the Top class. The class should have a single constructor that takes two input parameters: a String (for name) and int (for age). Your constructor should not have any redundant...
Question 2 What is the EXACT output of this code: class B { public B{ System.out.print("B"); } } class A extends B{ public A(int t) { super(); System.out.print("A"); } } public class Test{ public static void main(String[] args) { A a = new A(3); } }
What is output? public abstract class People { protected string name; protected int age; public abstract void PrintInfo(); public void PrintInformation() { System.out.println("In Base Class People"); public class Teacher extends People { private int experience; public void PrintInfo() { System.out.println("In Child Class Teacher"); public class Principal extends Teacher { public void PrintInformation() { System.out.println("In Child Class Principal"); public static void main(String args[]) { Principal tim; tim = new Principal(); tim.PrintInfo(); In Base Class People Error: Compiler error In Child Class...
2016 points output of following Java Program? public class Base { public final void show() { . System.out.println("Base::show() called"); public class Derived extends Base { public void show() { System.out.println("Derived::show() called"); } e lor rested in order public class Main { ects from and public static void main(String[] args) { Base b = new Derived(); b.show();
What is the output of the following code? class C1 { public double PI=3.1; public void m1() { System.out.println("M1 of C1"); } } class C2 extends C1 { public double PI=3.14; public void m1() { System.out.println("M1 of C2"); } } public class C { public static void main(String[] args) { C1 obj = new C2(); System.out.print(obj.PI); } } 3.1 3.14 None of the above
Consider the following classes (For Java): class A { public void process() { // Details omitted } } class B extends A { public void compute() { // Details omitted } } class C extends B { public void calculate() { // Details omitted } } Which of the following client code fragments are legal? Select one or more: C c = new C(); c.compute(); A c = new C(); c.process(); C c = new A(); c.process(); A a =...