Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
L

linaast

@linaast
About
Posts
2
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Inheritance,connection object.
    L linaast

    public class ConClass
    {
    public Connection con = null;

    // constructor to initialize con.
    public ConClass(DataSource ds){
    try{
    con = ds.getConnection();
    } catch(SqlException ex){
    System.out.println(ex.getMessage());
    }
    }
    // the con to get.
    public Connection getCon(){
    return con;
    }
    }

    public class SaveData
    {
    private Connection con = null;

    public void save(ConClass cObj){
    if(con == null){
    con = cObj.getCon();
    }
    // do whatever and use whenever you want your con in this class.
    }
    }

    Java question oop

  • problem with inheritance
    L linaast

    You do not need to create the instance into base class. If you have base class, leave it, every class, which extends the base class as father class makes instances to it automatically. All you need is to put "super" modifier, if u need to call any function from your base class. I suggest you to do like this in this case:

    public class OverrideTest{
    public static void main(String[] args){
    Derived dObj = new Derived();
    dObj.foo();
    }
    }

    public class Derived extends Base{
    public void foo(){
    System.out.println("In Derived.foo()");
    super.foo();
    }
    }

    public class Base{
    public void foo(){
    System.out.println("In Base.foo()");
    }
    }

    Now your output will be: "In Derived.foo()" "In Base.foo()" You do not need to use this:

    Base bObj = new Derived();

    If You want to call the foo() method of Base class directly from yor Main class, remove the foo() method from your Derived class. In this case, the foo() method will be called from Base class automatically.

    Java oop help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups