Technocrat

  • Home

Wednesday, November 12, 2014

Single Inhertance

 Sumit Kar     November 12, 2014     Java Programming     No comments   



Write a Program to
implement the concept of Single inheritance where Super Class and Subclass has
its own constructor and, all the variables in the super class are defined
protected.





Program:


class Rectangle


 {


  protected double l,b;





  Rectangle(double x,double y)


   {


    l=x;


    b=y;


   }


  double CalArea()


    {


     return (l*b);


    }


 }


class Box extends
Rectangle


 {


  double h;


  Box(double x,double y,double z)


   {


    super(x,y);


    h=z;


   }


  double CalVol()


    {


     return (l*b*h);


    }


 }


class Sk12


 {


 


  public static void main(String args[])


   {


    Box obj=new Box(5.5,6.5,7.5);


    double a= obj.CalArea();


    double v= obj.CalVol();


    System.out.println("Area= "+a);


    System.out.println("Vol= "+v);


    }


 }


Compile:


D:\>javac Sk12.java


Run:


D:\>java Sk12


Output:


Area= 35.75




Vol= 268.175


  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp
Email ThisBlogThis!Share to TwitterShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Pages

  • Home

Trending Now

  • Write a Program to Add two 3x3 Matrix using C
    #include<stdio.h> void main () { int a [ 3 ][ 3 ], b [ 3 ][ 3 ], s [ 3 ][ 3 ], i , j ; printf ( "Enter the values of ...
  • C program for Unit Conversion
    /* Convert Celsius to Fahrenheit */ #include<stdio.h> void main() {     float c,f;     printf("Enter the temperature in Celcius: ...
  • Addition of two numbers on Server sent from Client [TCP] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • Write a Program to Print the Truth Table of Basic Gates using C
  • Write a Program to Add two 5x5 Matrix using C
    #include<stdio.h> void main() {   int a[5][5],b[5][5],c[5][5];   int i,j;   for(i=0;i<5;i++)   {     printf("\nEnter elements ...
  • Using the concept of Inheritance write a C++ Program to calculate the area and perimeter of rectangle
    /* C++ Program to calculate the area and perimeter of rectangles using concept of inheritance. */ #include using namespace std; class Re...
  • Concatenation of two strings sent from Client on the Server - [ TCP ] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • 8085 Programming: Exchange the contents of memory locations
    Exchange the contents of memory locations 2000H and 4000H. Program 1: LDA 2000H : Get the contents of memory location 2000H into accumulator...
  • Calculate Depreciation using C
    #include<conio.h> #include<stdio.h> void main () { float sv , pv , dep ; int yos ; clrscr (); printf ( "Enter the pu...
  • 8085 Programming: 1's COMPLEMENT OF A 16-BIT NUMBER
    The 16bit number is stored in C050,C051 The answer is stored in C052,C053   LXI H,C050   MOV A,M   CMA   STA C052   INX H   MOV ...

Blog Archive

  • ►  2020 (1)
    • ►  May (1)
  • ►  2015 (92)
    • ►  October (4)
    • ►  September (3)
    • ►  August (3)
    • ►  July (9)
    • ►  June (9)
    • ►  May (20)
    • ►  April (7)
    • ►  March (22)
    • ►  February (7)
    • ►  January (8)
  • ▼  2014 (158)
    • ▼  November (70)
      • Binary Search in C using Recursion
      • Using the concept of Inheritance write a C++ Prog...
      • Java Program to implement Thread
      • 8085 Programming : store the nos in a memory loc. ...
      • 8085 Programming : In a set of nos add only the od...
      • 8085 Programming : In a set of nos add only the ev...
      • 8085 Programming : To find the no of 1’s in the byte
      • 8085 Programming : Block data transfer
      • 8085 Programming : Adding 2 Hexa-Decimal nos with ...
      • 8085 Programming : Adding 2 Hexa-decimal nos witho...
      • 8085 Programming: Adding 2 BCD nos without carry
      • 8085 Programming : ADDITION OF 16BIT NUMBERS
      • 8085 Programming : 8 BIT DECIMAL SUBSTRACTION
      • 8085 Programming: Exchange the contents of memory...
      • 8085 Programming: Store 8 bit data in Memory
      • 8085 Programming: 8 BIT MULTIPLICATION: PRODUCT 16...
      • 8085 Programming: 8 BIT DIVISION
      • 8085 Programming: 2's COMPLEMENT OF AN 8-BIT NUMBER
      • 8085 Programming: 2's COMPLEMENT OF A 16-BIT NUMBER
      • 8085 Programming: 1's COMPLEMENT OF AN 8-BIT NUMBER
      • 8085 Programming: 1's COMPLEMENT OF A 16-BIT NUMBER
      • 8085 Programming :
      • Nokia's first device to the post Microsoft era
      • Durga Puja Maps
      • WhatsApp add new features to Group Chat : Multiple...
      • Firefox dumps Google, signs with Yahoo as default ...
      • Your ATM Usage Pattern Need Not Hurt Your Pocket
      • Read Receipts: WhatsApp - Lets you disable Blue T...
      • Solve All-Pairs Shortest Path Problem using Floyd–...
      • Applet code to generate a smiley
      • Single Inheritance using Java
      • Implement Try - Catch block using Java
      • Implement Exception handling using Java
      • Implement array of Objects using C++
      • Implement abstract class with Single Inheritance
      • Multiple Inheritance
      • Hierarchical Inheritance
      • Multi Level Inheritance
      • Call parameterized method define in a class from t...
      • Parameterized Method Overloading using Java
      • Parameterized Method using Java
      • Copy Constructor using Java
      • Constructor Overloading
      • Parameterized constructor using Java
      • Factorial of a number using Java
      • Prime Check using Java
      • Java Program to display “Hello, World !”
      • Insertion Sort
      • Prim's Algorithm
      • Pattern Printing using Java
      • Abstract Class
      • Implement the concept of interface using Java
      • Object reference or Copy Constructor using Java
      • Print Details using C++
      • Find the Size of a Class and object in C++
      • Find Simple Interest using C++
      • Print the digits of a number in words using C++
      • Use of Protected Access Specifier
      • Try single level inheritance with Super Class as F...
      • Overriding as overloading
      • Method Overriding
      • Single Inhertance
      • Nokia - Is it an End or Beginning of a New Era?
      • Microsoft Lumia Devices - #MoreLumia
      • WhatsApp's Blue Tick: Really an Upgrade or a menace ?
      • How to Install Android Apps on SD Card
      • Command Prompt Tricks
      • Trick to use dual number on WhatsApp from a Single...
      • C Program
      • Use Visual Studio to Build Android Apps
    • ►  October (6)
    • ►  September (82)
Powered by Blogger.

Categories

C - Programming Java Programming Basic Technology 8085 Assembly Programming For Loop Numerical Methods WhatsApp Algorithm Shell Programming Programming Networking Windows Android C++ Programming CPP If Else Tricky Internet Microsoft Pattern Photography Socket Program News While Loop Array DBMS DS Macro Recursion User Defined Function Conditional Operator Data Structure Durga Puja Earthquake Google Mela Nokia SQL Share Yahoo Airtel Bio Command Prompt Confused Facebook Finance Firefox Ganges Graph HokKolorob Input Kolkata MCQ Math Matrix NetNeutrality Oracle Religion Search Sumit Kar Survey Switch Case Viral Virus Visual Studio do-while featured featured_slider

Popular Programs

  • Write a Program to Add two 3x3 Matrix using C
    #include<stdio.h> void main () { int a [ 3 ][ 3 ], b [ 3 ][ 3 ], s [ 3 ][ 3 ], i , j ; printf ( "Enter the values of ...
  • C program for Unit Conversion
    /* Convert Celsius to Fahrenheit */ #include<stdio.h> void main() {     float c,f;     printf("Enter the temperature in Celcius: ...
  • Addition of two numbers on Server sent from Client [TCP] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • Write a Program to Print the Truth Table of Basic Gates using C
  • Write a Program to Add two 5x5 Matrix using C
    #include<stdio.h> void main() {   int a[5][5],b[5][5],c[5][5];   int i,j;   for(i=0;i<5;i++)   {     printf("\nEnter elements ...
  • Using the concept of Inheritance write a C++ Program to calculate the area and perimeter of rectangle
    /* C++ Program to calculate the area and perimeter of rectangles using concept of inheritance. */ #include using namespace std; class Re...
  • Concatenation of two strings sent from Client on the Server - [ TCP ] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • 8085 Programming: Exchange the contents of memory locations
    Exchange the contents of memory locations 2000H and 4000H. Program 1: LDA 2000H : Get the contents of memory location 2000H into accumulator...
  • Calculate Depreciation using C
    #include<conio.h> #include<stdio.h> void main () { float sv , pv , dep ; int yos ; clrscr (); printf ( "Enter the pu...
  • 8085 Programming: 1's COMPLEMENT OF A 16-BIT NUMBER
    The 16bit number is stored in C050,C051 The answer is stored in C052,C053   LXI H,C050   MOV A,M   CMA   STA C052   INX H   MOV ...

Daily Hits

Copyright © Sumit Kar