Question: What is the output for the following program codes? a) [ 0.5 Mark ] class A { int i; } class B extends A {

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:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!