Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › How to create sublass ?
New Posts  All Forums:Forum Nav:

How to create sublass ? - Page 2

post #11 of 14
Quote:
Originally Posted by Barbaroti View Post

Couldn't he also do it like this?
Code:
public class C 
{
    protected int m;
    protected int n;
    
    public C(int mIn , int nIn)
    {
        m=mIn;
        n=nIn;
    }
    
    public int m1()
    {
        return m+n;
    }
}
Code:
public class B extends C{
    public B(int mIn, int nIn) {
        super(mIn, nIn);
    }    
    
    @Override
    public int m1()
    {
        return m*n;
    }
}

or like this biggrin.gif
    
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz @ 1.34V Asus rampage extreme IV Shaphire 6950 unlocked to 6970 Corsair Dominators GT 16GB 4GBX4 OCed @ 2400MHz... 
Hard DriveHard DriveOptical DriveCooling
Intel SSD 330 series 180GB WD Black 1TB 64Mb Cache + Blue 500GB 16mb Cache... LG DVD EK-Supreme HF - EN (Nickel) 
CoolingCoolingCoolingCooling
EK-FB KIT RE4 - Acetal Laing D5 Vario 12V DC Pump (MCP 655)  EK-BAY SPIN Reservoir - Plexi EK-CoolStream RAD XT (240) 
CoolingOSMonitorKeyboard
EK-CoolStream RAD XTX (120) Windows 7 64-bit LG W2261 22inch 1920X1080@60Hz Razer Lycosa 
PowerCase
Cooler Master Silent Pro Gold 1000W Thermaltake Level 10 GT 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz @ 1.34V Asus rampage extreme IV Shaphire 6950 unlocked to 6970 Corsair Dominators GT 16GB 4GBX4 OCed @ 2400MHz... 
Hard DriveHard DriveOptical DriveCooling
Intel SSD 330 series 180GB WD Black 1TB 64Mb Cache + Blue 500GB 16mb Cache... LG DVD EK-Supreme HF - EN (Nickel) 
CoolingCoolingCoolingCooling
EK-FB KIT RE4 - Acetal Laing D5 Vario 12V DC Pump (MCP 655)  EK-BAY SPIN Reservoir - Plexi EK-CoolStream RAD XT (240) 
CoolingOSMonitorKeyboard
EK-CoolStream RAD XTX (120) Windows 7 64-bit LG W2261 22inch 1920X1080@60Hz Razer Lycosa 
PowerCase
Cooler Master Silent Pro Gold 1000W Thermaltake Level 10 GT 
  hide details  
Reply
post #12 of 14
Thread Starter 
then what should i type to let it print out ?
system.print.ln (m-n ??)
post #13 of 14
First, you need to create a variable of type B/C. Then, if you want the result of m1 simply call the function that does the job.
Here is pretty much an example using your code:
Code:
public static void main(String[] args) {
        // TODO code application logic here
        C c = new C(5,3);
        B b = new B(5,3);
        System.out.println(c.m1());
        System.out.println(b.m1());
    }
Quote:
Originally Posted by Yeong View Post

then what should i type to let it print out ?
system.print.ln (m-n ??)

If you were to do it like that, in my opinion, there would be no point to have the function, since you will be doing the operation outside it anyways.
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
First Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
i7-2600k @4.5Ghz Gigabyte Z68X-UD7 B3 MSI 6950 G.Skill Sniper 2x4GB 
Hard DriveHard DriveHard DriveCooling
Crucial M4 64GB Samsung SpinPoint 250GB Hitachi 1TB Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows Server 2012 Samsung S22B300 22' ViewSonic VA703B 17" CM Quickfire TK 
PowerCaseMouse
Corsair HX850 NZXT Phantom Mionix Naos 3200 
  hide details  
Reply
post #14 of 14
Thread Starter 
I had done with it and its works !
Thank you so much ! thumb.gifthumb.gif
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › How to create sublass ?