0% found this document useful (0 votes)
29 views

Experiment No.-1.4: 2.task To Be Done

The document describes an experiment conducted by a student to learn different types of inheritance in Java. It includes code examples demonstrating single inheritance, multilevel inheritance, multiple inheritance, and interface inheritance. The code is compiled and run to generate output validating the inheritance concepts.

Uploaded by

Surbhi Rajput
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Experiment No.-1.4: 2.task To Be Done

The document describes an experiment conducted by a student to learn different types of inheritance in Java. It includes code examples demonstrating single inheritance, multilevel inheritance, multiple inheritance, and interface inheritance. The code is compiled and run to generate output validating the inheritance concepts.

Uploaded by

Surbhi Rajput
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

EXPERIMENT NO.-1.

STUDENT NAME-SURBHI RAJPUT UID-20BCS9830

BRANCH-CSE SECTION-20BCS43-B

1.AIM-Program to learn different types of inheritance in java.

2.TASK TO BE DONE-1.Writing the program code with


required tasks
2.Compiling the program and generating the output

3.CODE-
import java.io.*;
import java.lang.*;
import java.util.*;

class one {
public void print_inheritance()
{
System.out.println("single inheritance");
}
}

class two extends one {


public void print_for() { System.out.println("for"); }
}
// Driver class
public class Main {
public static void main(String[] args)
{
two g = new two();
g.print_inheritance();
g.print_for();
g.print_inheritance();
}
}
OUTPUT

CODE-
import java.io.*;
import java.lang.*;
import java.util.*;

class one {
public void print_inheritance()
{
System.out.println("MULTILEVEL");
}
}

class two extends one {


public void print_for() { System.out.println("for"); }
}

class three extends two {


public void print_inheritance()
{
System.out.println("MULTILEVEL");
}
}

// Drived class
public class Main {
public static void main(String[] args)
{
three g = new three();
g.print_inheritance();
g.print_for();
g.print_inheritance();
}
}
OUTPUT
CODE-
class A {
public void print_A() { System.out.println("Class A"); }
}

class B extends A {
public void print_B() { System.out.println("Class B"); }
}

class C extends A {
public void print_C() { System.out.println("Class C"); }
}
class D extends A {
public void print_D() { System.out.println("Class D"); }
}

// Driver Class
public class Test {
public static void main(String[] args)
{
B obj_B = new B();
obj_B.print_A();
obj_B.print_B();

C obj_C = new C();


obj_C.print_A();
obj_C.print_C();

D obj_D = new D();


obj_D.print_A();
obj_D.print_D();
}
}
OUTPUT

CODE
import java.io.*;
import java.lang.*;
import java.util.*;

interface one {
public void print_inheritance();
}

interface two {
public void print_for();
}

interface three extends one, two {


public void print_inheritance();
}
class child implements three {
@Override public void print_inheritance()
{
System.out.println("multiple");
}

public void print_for() { System.out.println("for"); }


}

// Drived class
public class Main {
public static void main(String[] args)
{
child c = new child();
c.print_inheritance();
c.print_for();
c.print_inheritance();
}
}
OUTPUT

You might also like