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
What is abstraction oop?
write a code for this. serial_number contained in the header of the file will be read , if this serial number is less than a previous serial number within a successfully processed file, or is the same as another serial number within a successfully processed file, or if the field contains anything other than 7 digits, then the file must error with the reason ‘Invalid SERIAL_NUMBER’.
How many human genes are polymorphic?
What exactly is polymorphism?
What does oop mean in snapchat?
Can a destructor be called directly?
What is polymorphism explain its types?
What are main features of oop?
what is difference between class template and template class?
What is overriding vs overloading?
What is difference between multiple inheritance and multilevel inheritance?
Explain the advantages of inheritance.
which feature are not hold visual basic of oop?
What is this pointer in oop?
Write a program to sort the number with different sorts in one program ??