Skip to main content

Implementation of Hybrid inheritance in Java


Implementation of Hybrid inheritance in Java with the help of INTERFACE


CODE>>


class Student
{
    int rollNumber;
    void getNumber(int n)
    {
        rollNumber=n;
    }
    void putNumber()
    {
        System.out.println("Roll No :: "+rollNumber);
    }  
}


class Test extends Student
{
    float part1,part2;
    void getMarks(float m1,float m2)
    {
        part1=m1;
        part2=m2;
    }
    
    void putMarks()
    {
        System.out.println("Marks Obtained\n");
        System.out.println("PART1: "+part1);
        System.out.println("PART2: "+part2);
    }
}


interface Sports
{
    float sportWt=6.0F;
    void putwt();
}


class Results extends Test implements Sports
{
    float total;
    public void putwt()
    {
        System.out.println("Sports Wt="+sportWt);
    }
    void display()
    {
        total=part1+part2+sportWt;
        putNumber();
        putMarks();
        putwt();
        System.out.println("Total Score= "+total);
    }
}


class hybrid
{
    public static void main(String args[])
    {
        Results student1=new Results();
        student1.getNumber(1234);
        student1.getMarks(17.4F, 33.0F);
        student1.display();
    }
}

Comments

Popular posts from this blog

Java Sample: While loop

public class whilechk1 {     public static void main(String args[])     {         int row,column,y;         System.out.print("\nMultiplication Table\n");         row=1;         do         {             column=1;             do             {                 y=row*column;                 System.out.print("\t"+y);                 column++;             }while(column<=10);             System.out.println("\n");             row++;         }while(row<=10);     } }

A Hit Count Using Java Servlet's Session Tracking

import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class SessionTracker extends HttpServlet {         public void doGet(HttpServletRequest req,HttpServletResponse res)         throws ServletException,IOException         {                res.setContentType("text/html");                PrintWriter out=res.getWriter();                HttpSession session=req.getSession(true);                Integer count=(Integer)session.getValue("tracker.count");                if(count==null)       ...

Hi! I'm Java...

Java is a computer programming language. It enables programmers to write computer instructions using English based commands, instead of having to write in numeric codes. It’s known as a “high-level” language because it can be read and written easily by humans. Like English, Java has a set of rules that determine how the instructions are written. These rules are known as its “syntax”. Once a program has been written, the high-level instructions are translated into numeric codes that computers can understand and execute. Who Created Java? In the early nineties, Java was created by a team led by James Gosling for Sun Microsystems. It was originally designed for use on digital mobile devices, such as cell phones. However, when Java 1.0 was released to the public in 1996, its main focus had shifted to use on the Internet. It provided more interactivity with users by giving developers a way to produce animated webpages . Over the years it has evolved as a successful language for ...