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 {
public void getCar(){
System.out.println("Swift car"); }}
class inheritance {
public static void main(String args[]) {
Parent p = new Parent();
p.getBike();
Child c = new Child();
c.getBike();
c.getCar(); }}
OUTPUT:
a) 2 3
Explanation: After declaration of obj, we assigned values i = 1 and j = 2. But when we call display, we are updating i value as super.i = j+1 = 2 + 1 = 3. As class B inherits i from A, it prints i values as 3. So, output is 2 3
b)
Suzuki Bike
Suzuki Bike
Swift car
Explanation: Parent p calls getbike(), which displays "Suzuki Bike". Child c also calls getBike(), which inherited getBike() method from Parent, it also prints "Suzuki Bike". Then Child c call getCar() method which prints "Swift car"
What is the output for the following program codes? a) [ 0.5 Mark ] class A...
a. Mention the appropriate relationship between following classes: [0.5 Marks] 1. HOD–StaffMember 2. Car–Ferrari 3. Student-Address 4. BankAccount–FixedAccount 5. House-Building 6. Department-Teacher 7. Traffic–TrafficSign b. Provide the UML diagram for the following program. [ 0.5 Marks] class Parent { public void getBike() { System.out.println("Suzuki Bike"); } } class Child extends Parent { public void getCar() { System.out.println("Swift car"); } } class inheritance { public static void main(String args[]) { Parent p = new Parent(); p.getBike(); Child c = new Child();...
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 output of the following code? class parent { public void someFunction() { System.out.println("Parent Function"); } } public class child extends parent { public void someFunction() { System.out.println("Child Function"); } public static void main(String args) { parent p1 = new parent(); parent p2 = new child(); child c1 = new child(); p1.someFunction(); p2.someFunction(); c1.someFunction(); } }
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
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(); obj.m1(); } } M1 of C1 M1 of C2 None of the above
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...
Help with a question in Java: What is the output from the following program? public class Methods2 { public static void main(String[] args) { for (int i = 0; i < 3; i++) { for (int j = 0; j <= i; j++){ System.out.print(fun(i, j) + "\t"); } System.out.println(); } } static long fun(int n, int k) { long p = 1; while (k > 0){ p *= n; } return p; } }
What is the output of the following codes? Line1: public class ArrayCompare ! Line2: public static void main (String[] args) { Line 3: int arr1[] = {1, 2, 3); Line4: int arr2[] = {1, 2, 3); Line5: if (arri == arr2) Line 6: System.out.println("Same"); Line 7: else Line 8: System.out.println("Not same"); Line9 : Line10: ) } Not same Same
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
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...