1. what is the output of following program:
- package com.instanceofjava;
- public class SuperDemo{
- public void show(){
- System.out.println("super class method called");
- }
- }
- package com.instanceofjava;
- public class SubDemo extends SuperDemo{
- public void show(){
- System.out.println("sub class method called");
- }
- public static void main(String args[]){
- SubDemo subobj=new SubDemo();
- subobj.show();
- }
2. what is the output of following program:
- package com.instanceofjava;
- public class SuperDemo{
- int x;
- }
- package com.instanceofjava;
- public class SubDemo extends SuperDemo{
- int y;
- public void show(){
- super.x=y+2;
- System.out.println("x="+super.x+"y="+y);
- }
- public static void main(String args[]){
- SubDemo subobj=new SubDemo();
- subobj.show();
- }
3. what is the output of following program:
- package com.instanceofjava;
- public class SuperDemo {
- int x;
- }
- package com.instanceofjava;
- public class SubDemo extends SuperDemo{
- int y;
- public void show(){
- super.x=y+2;
- System.out.println("x="+super.x+"y="+y);
- }
- public static void main(String args[]){
- SubDemo subobj=new SubDemo();
- subobj.x=2;
- subobj.y=2;
- subobj.show();
- }
4. what is the output of following program:
- package com.instanceofjava;
- public class SuperDemo{
- int x;
- SuperDemo(){
- x=24;
- }
- }
- package com.instanceofjava;
- public class SubDemo extends SuperDemo{
- int y;
- public void show(){
- System.out.println("x="+super.x);
- System.out.println("y="+y);
- }
- public static void main(String args[]){
- SubDemo subobj=new SubDemo();
- subobj.show();
- }
superr...
ReplyDeleteHow we can solve super.x=y+2;
ReplyDeleteand we will get output as x=2, y=0
in 2nd program.