Answer Posted / rahul
execute this program and you will get your answer
class base
{
public int i,j;
}
class drived extends base
{
public int k;
}
class main
{
public static void main(String[] s)
{
base b = new base();
drived d = new drived();
b.i=10;
b.j=20;
System.out.println("this is class base i=10,j=20");
System.out.println("i =" +b.i);
System.out.println("j =" +b.j);
System.out.println("this is class drived i=100,j=200,k=300");
d.i=100;
d.j=200;
d.k=300;
System.out.println("i =" +d.i);
System.out.println("j =" +d.j);
System.out.println("k =" +d.k);
b=d;
System.out.println("after the assignment");
System.out.println("i =" +b.i);
System.out.println("j =" +b.j);
//System.out.println("k =" +b.k);
System.out.println("even though i am calling i and j using b object it is showing d values and you cannot call k this is called object sclicing object d got scliced now you cannot access k after the assignment of d into b");
}
}
| Is This Answer Correct ? | 7 Yes | 7 No |
Post New Answer View All Answers
Can we create object of interface?
Why is static class not inherited?
Why do we use class?
What are properties in oop?
What is the difference between abstraction and polymorphism?
INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?
What is the oops and benefits of oops programming?
write a program to find 2 power of a 5digit number with out using big int and exponent ?
c++ program to swap the objects of two different classes
Can destructor be overloaded?
What is interface in oop?
write a program using c++ to implement single contiguous memory mangement techniques.display the content of the main memory after yhe allocation of jobs and percentage of the wastage of the main memory
How to handle exception in c++, For example in a functions i am assigning memory to some variables and also in next instructions in am dividing one variable also. If this functions generates a error while allocating memory to those variable and also while dividing the variable if i divide by zero then catch block how it will identify that this error has cone from perticular instruction
What is overloading and its types?
write a code for this:trailer recordId contains a value other than 99, then the file must error with the reason ‘Invalid RECORD_ID’(User Defined Exception).