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
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).
Why we use classes in oop?
What is inheritance and how many types of inheritance?
What is object in oop?
What is the highest level of cohesion?
Why interface is used?
What is encapsulation in oops?
String = "C++ is an object oriented programming language.An imp feature of oops is classes and objects".Write a pgm to count the repeated words from this scenario?
Why multiple inheritance is not allowed?
What is polymorphism and why is it important?
How Do you Code Composition and Aggregation in C++ ?
What is use of overloading?
What is object-oriented programming? Webopedia definition
How to improve object oriented design skills?
what type of questions