How many lines of output are provided by this program?
public class PrintLines
{
public static void main(String[ ] args)
{
System.out.println(“Two…”);
System.out.println(“One…”);
System.out.println(“Zero…”);
System.out.println(“Liftoff!…”);
System.out.println(“Houston, we have a problem…”);
}
}
2
4
3
5
Ans. 5
The program prints 5 different lines and each System.out.println statement prints the words in the parantheses and a new line as well. This causes the next println to be printed in the next line. So, 5 println statements make 5 different lines of output.
How many lines of output are provided by this program? public class PrintLines { public static...
What output is produced by the following program? public class MysteryNums public static void main(String[] args) - int x = 12; int y = x - 3; 3, sentence (y, x + y); . public static void sentence (int numi, int num2) { 4: System.out.println(num1 + " + num2);
1) Consider the following Java program: 1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...
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();
Show the output of running the class Test in the following code lines: interface A { void print (); } class C ( class B extends C implements A { public void print() { } } class Test { public static void main(String[] args) { B b = new B(); if (b instanceof A) System.out.println("b is an instance of A"); w class Test { public static void main(String[] args) { B b = new B(); if (b instanceof A) System.out.println("b...
What is the output for the following program codes? a) [ 0.5 Mark ] class A { int i; } class B extends A { int j; void display() { super.i = j + 1; System.out.println(j + " " + i); }} class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); }} OUTPUT: b) [ 0.5 Mark ] class Parent { public void getBike(){ System.out.println("Suzuki Bike"); }} class Child extends Parent {...
What is the output of the following code? Explain your answer. public class Test {public static void main (String [] args) {System.out. print((int) 5.6); System.out.println((int) 5.2);}}
public class Polymorph public static class CAL public void printHello System.out.println("Hya"); public static class w extends CAC public void printHello System.out.println("Howdy"); public static class PB extends WE public void printtello System.out.println("Hello") public static void main(String[] args) { A l = new CÁO: CA ab - (CA) new W(); CA ac - (CA) new PC); Wbc - (W) new P80; 33.printHello(); ab.printHello(); ac.printHello(); be.printHello(); Type your answer, do not copy/paste
What is the output of this program? class A { public int i; private int j; } class B extends A { void display() { super.j = super.i + 1; System.out.println(super.i + " " + super.j); } } class Inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } Java language!! // include explanation!
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"); } }
What is the output of the following codes? Line1: public class ArrayCompare { Line2: public static void main (String[] args) { Line 3: int arrill {1, 2, 3}; Line 4: int arr2[1 {1, 2, 3}; Line5: if (arri == arr2) Line 6: System.out.println("Same"); Line: else Line 8: System.out.println("Not game"); Line9 : Line10:) حسین Same Not same