Search Results

Search found 22413 results on 897 pages for 'train main'.

Page 152/897 | < Previous Page | 148 149 150 151 152 153 154 155 156 157 158 159  | Next Page >

  • Java game design question (graphical objects)

    - by vemalsar
    Hello Guys, I'm beginner in game development, in Java and here on this site too and I have a game design question. Please comment my idea: I have a main loop which call update and draw method. I want to use an ArrayList which store graphical objects, they have coordinate and image or text to draw and my game objects extends this class. In update, I can choose which objects should be put in the array and in draw method I'll display the elements of array on the screen. I'm using a buffer and draw first there, but it is not important now I guess...Here is a simple (not full) code, only the logic: public class GamePanel extends JPanel implements KeyListener { ArrayList<graphicalObjects> graphArray = new ArrayList<graphicalObjects>(); public void update() { //change the game scene, update the graphArray, process input etc. } public void draw() { //draws every element of graphArray to a JPanel } public static main(String[] args) { while(true) { update(); draw(); } } } My questions: Should have I use interface or abstract class for graphicalObjects? graphicalObjects class and the ArrayList really needs or there is some better solution? How to draw objects? They draw themself with their own method or in the draw method I have to draw manually based on graphicalObjects variables (x,y coordinates, image etc.)? If this conception is wrong, please suggest another one! All comments are welcome and sorry if this is dumb question, thanks!

    Read the article

  • Splitting a tetris game apart - where to put time-management?

    - by nightcracker
    I am creating a tetris game in C++ & SDL, and I'm trying to do it "good" by making it object-oriented and keeping scopes small. So far I have the following structure: A main with some lowlevel SDL set up and handling input A game class that keeps track of score and provides the interface for main (move block down, etc) A map class that keeps track of the current game field, which blocks are where. Used by the game class. A block class that consists of the current falling block, used by game. A renderer class abstracting low level SDL to a format where you render "tetris blocks". Used by map and block. Now I have a though time where to place the time-management of this game. For example, where should be decided when a block bumps the bottom of the screen how long it takes the current block locks in place and a new block spawns? I also have an other unrelated question, is there some place where you can find some standard data on tetris like standard score tables, rulesets, timings, etc?

    Read the article

  • Nginx, logrotate and empty files

    - by tzulberti
    I have a problem with nginx/logrotate. The problems is that nginx is logging access to 2 files (main and data). I have the following contrab setting: 0 * * * * /usr/sbin/logrotate -f /home/orwell/orwell-setup/bin/logrotate-nginx And the file "logrotate-nginx" has the following content: /tmp/data.log { rotate 90 daily missingok notifempty size 1 sharedscripts postrotate [ ! -f /tmp/nginx.pid ] || kill -USR1 `cat /tmp/nginx.pid` MORE THINGS endscript } /tmp/main.log { rotate 90 daily missingok notifempty size 1 sharedscripts postrotate [ ! -f /tmp/nginx.pid ] || kill -USR1 `cat /tmp/nginx.pid` MORE THINGS endscript } The work is done in the two files, but there is a problem that nginx stops logging into those files. Both files are created, but they are empty. Any ideas why nginx stop logging info to both files?

    Read the article

  • Linux and Windows machines sharing a network

    - by Saif Bechan
    I have different Windows and Linux machines that share an internal private network. From within this network I can SSH to every machine etc. This internal network works great. I have my main windows machine from where I control these machines either trough SSH or virtual desktop. Is there a way for me on my main machine to see all the machines that are connected to the network. I want to be able to see all the machines and maybe browse them, share files etc. I am very new to networking of this kind so any recommendations are welcome. Should I set up this network by workgroup? I do not think Linux supports that. Or should I set up the network with domain, I never did that before.

    Read the article

  • Squid stale-while-revalidate not working when max-age=0

    - by Wiliam
    Squid 2.7 always reaches backend, expected is to reach backend using stale-while-revalidate only when cache expires, not when client triggers max-age=0. Script: <?php header('Cache-Control: public, max-age=10, stale-if-error=200, stale-while-revalidate=500'); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); sleep(2); die("OK"); And squid config: # http_port public_ip:port accel defaultsite= default hostname, if not provided http_port 80 accel defaultsite=mydomain.com # IP and port of your main application server (or multiple) cache_peer 127.0.0.1 parent 8000 0 no-query allow-miss originserver name=main # Do not tell the world that which squid version we're running httpd_suppress_version_string on # Remove the Caching Control header for upstream servers header_access Cache-Control deny all #header_access Last-Modified deny all # log all incoming traffic in Apache format logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh access_log /usr/local/squid/var/logs/squid.log combined all cache_effective_user squid refresh_pattern . 10080 90% 999999 ignore-no-cache override-expire ignore-private icp_port 0

    Read the article

  • Resource Acquisition is Initialization in C#

    - by codeWithoutFear
    Resource Acquisition Is Initialization (RAII) is a pattern I grew to love when working in C++.  It is perfectly suited for resource management such as matching all those pesky new's and delete's.  One of my goals was to limit the explicit deallocation statements I had to write.  Often these statements became victims of run-time control flow changes (i.e. exceptions, unhappy path) or development-time code refactoring. The beauty of RAII is realized by tying your resource creation (acquisition) to the construction (initialization) of a class instance.  Then bind the resource deallocation to the destruction of that instance.  That is well and good in a language with strong destructor semantics like C++, but languages like C# that run on garbage-collecting runtimes don't provide the same instance lifetime guarantees. Here is a class and sample that combines a few features of C# to provide an RAII-like solution: using System; namespace RAII { public class DisposableDelegate : IDisposable { private Action dispose; public DisposableDelegate(Action dispose) { if (dispose == null) { throw new ArgumentNullException("dispose"); } this.dispose = dispose; } public void Dispose() { if (this.dispose != null) { Action d = this.dispose; this.dispose = null; d(); } } } class Program { static void Main(string[] args) { Console.Out.WriteLine("Some resource allocated here."); using (new DisposableDelegate(() => Console.Out.WriteLine("Resource deallocated here."))) { Console.Out.WriteLine("Resource used here."); throw new InvalidOperationException("Test for resource leaks."); } } } } The output of this program is: Some resource allocated here. Resource used here. Unhandled Exception: System.InvalidOperationException: Test for resource leaks. at RAII.Program.Main(String[] args) in c:\Dev\RAII\RAII\Program.cs:line 40 Resource deallocated here. Code without fear! --Don

    Read the article

  • Sharing files between multiple sites using only desktop software

    - by perlyking
    Our organisation has three sites; a head office, where the master copies of company files are stored, plus two branch offices using only workstations and a NAS or two. Currently we're talking about <10GB. At the main office, we have no admin access to the file server, as this is entirely controlled by the larger institution where we are located. For the same reason, we have no VPN remote access to this network. Instead, we simply have access to a network share using over a Novell LAN. Question: how can we share files between offices in way that minimises latency, i.e. that gives us a mirror of the main network share at each site? (There is little likelihood of concurrent editing, and we can live with the odd file conflict now and again). Up to now branch office staff have had to use GotoMyPC-type solutions to remotely access files held at the main office. Or email. I was hoping to use Google Drive on a dedicated workstation at each office to sync the contents of the network share (head office) or NAS (branch offices) via the cloud, but at my last attempt (29 Jun '12), the Google Drive installer would not allow me to designate the remote network share as the "target" folder. (I chose Google Drive over Drobbox et al. as we already use GMail for corporate mail) The next idea was to use a designated workstation at head office to mirror the network share to a local drive, then use Google Drive to push that to the cloud. This seems a step too far. Nor do I have any good ideas about how to achieve this network/local mirroring, as we can't, for example, install the rsync daemon on the server. I do not want to use Google Drive locally on each workstation as this will inconvenience users, and more importantly, move files off the backed-up, well-maintained (UPS, RAID etc) network share at head office. Our budget is only in the £100's. Should we perhaps just ditch the head office server and use something like JungleDisk? At least this presents the user with what appears to be a mapped drive.

    Read the article

  • Splitting Pygame functionality between classes or modules?

    - by sec_goat
    I am attempting to make my pygame application more modular so that different functionalities are split up into different classes and modules. I am having some trouble getting pygame to allow me to draw or load images in secondary classes when the display has been set and pygame.init() has been done in my main class. I have typically used C# and XNA to accomplish this sort of behavior, but this time I need to use python. How do I init pygame in class1, then create an instance of class2 which loads and converts() images. I have tried pygame.init() in class 2 but then it tells me no display mode has been set, when it has been set in class1. I am under the impression i do not wnat to create multiple pygame.displays as that gets problematic I am probably missing something pythonic and simple but I am not sure what. How do I create a Display class, init python and then have other modules do my work like loading images, fonts etc.? here is the simplest version of what I am doing: class1: def __init__(self): self.screen = pygame.display.set_mode((600,400)) self.imageLoader = class2() class2: def __init__(self): self.images = ['list of images'] def load_images(): self.images = os.listdir('./images/') #get all images in the images directory for img in self.images: #read all images in the directory and load them into pygame new_img = pygame.image.load(os.path.join('images', img)).convert() scale_img = pygame.transform.scale(new_img, (pygame.display.Info().current_w, pygame.display.Info().current_h)) self.images.append(scale_img) if __name__ == "__main__": c1 = class1() c1.imageLoader.load_images() Of course when it tries to load an convert the images it tells me pygame has not been initialized, so i throw in a pygame.init() in class2 ( i have heard it is safe to init multiple times) and then the error goes to pygame.error: No video mode has been set

    Read the article

  • Export 1 year of CVS to another repo?

    - by John Dibling
    We have a CVS repo with many years of history. It has become huge and unwieldly, so we would like to split this singe repo in to two repos: The main repo would have 1 year's worth of history, up to and including present day. This is where all dev work would take place. An archive repo would have the complete history, up to the point where the main repo would take over. This would be read-only, and only used to look at historical changes. Given that we are starting with one huge, monolithic CVS repo, is it possible to split it up in this way? How can this be accomplished?

    Read the article

  • Setting up Multiple Routers (as Hardware Firewalls) behind a Home Router

    - by Synetech
    I’ve currently got one computer behind a router with built-in firewall functionality, connected to a home cable-modem that has a single Ethernet port and one IP. I’m going to have to set up another computer for the rest of the family to use which of course will need to be connected to the Internet, probably wirelessly since the modem is in my room and the new system would not be. What I would like to do is to get two more small routers with firewall capability and connect each computer to a router, which would in turn connect to the main router which connects to the cable-modem. That way, both systems have a hardware firewall protecting them (particularly the wireless system) and the burden of blocking would be reduced on both the computer CPUs and the main router because the secondary routers would handle some of the workload. I’m trying to find out about the complexities inherent in this design and how I could set it up to work, specifically the IP handling and NAT aspect. Thanks a lot.

    Read the article

  • How to delete "System Volume Information" folder from external drives?

    - by Nadude
    I'm running Vista Prof 32bit on a lenovo w500 thinkpad. I have four external drives and use 4 different PCs, that all have system volume information folders, taking up lots of space, and I can't delete them. I don't even know which computer's files are backed up on which external. I've used Thinkvantage rescue and recovery to delete all backups, as well as checked system restore settings to only use my main C drive. I checked all the PC's to ensure only the Main drive keeps system restore points and deleted previous versions. I ran Disc Clean up too. But I can't figure out how to get rid of these large folders from my external drives.

    Read the article

  • Router used as ethernet bridge wont show up

    - by user1255271
    I have a Netgear router in my living room that has the wireless signal. It is connected to a Powerline plug that goes up to my bedroom. That is plugged into another router that is used as an ethernet hub. It's cables go into my PS3 and my server. The second router shows up as a hidden network on my laptop, and I can connect to it. But it is not listed as an attached device on my main router, and my laptop says that it connects straight to the main router, not the second one. How can I connect to this router? Aside from swapping the two? Thanks in advance.

    Read the article

  • OpenGL depth texture wrong

    - by CoffeeandCode
    I have been writing a game engine for a while now and have decided to reconstruct my positions from depth... but how I read the depth seems to be wrong :/ What is wrong in my rendering? How I init my depth texture in the FBO gl::BindTexture(gl::TEXTURE_2D, this->textures[0]); // Depth gl::TexImage2D( gl::TEXTURE_2D, 0, gl::DEPTH32F_STENCIL8, width, height, 0, gl::DEPTH_STENCIL, gl::FLOAT_32_UNSIGNED_INT_24_8_REV, nullptr ); gl::TexParameterf(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST); gl::TexParameterf(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST); gl::TexParameterf(gl::TEXTURE_2D, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE); gl::TexParameterf(gl::TEXTURE_2D, gl::TEXTURE_WRAP_T, gl::CLAMP_TO_EDGE); gl::FramebufferTexture2D( gl::FRAMEBUFFER, gl::DEPTH_STENCIL_ATTACHMENT, gl::TEXTURE_2D, this->textures[0], 0 ); Linear depth readings in my shader Vertex #version 150 layout(location = 0) in vec3 position; layout(location = 1) in vec2 uv; out vec2 uv_f; void main(){ uv_f = uv; gl_Position = vec4(position, 1.0); } Fragment (where the issue probably is) #version 150\n uniform sampler2D depth_texture; in vec2 uv_f; out vec4 Screen; void main(){ float n = 0.00001; float f = 100.0; float z = texture(depth_texture, uv_f).x; float linear_depth = (n * z)/(f - z * (f - n)); Screen = vec4(linear_depth); // It ISN'T because I don't separate alpha } When Rendered so gamedev.stackexchange, what's wrong with my rendering/glsl?

    Read the article

  • WUBI installation can no longer boot, UUID disk not found

    - by Joel Heenan
    Yesterday my Wubi/Vista installation was working fine. I shut it down at the train station, all good then when I attempted to boot ubuntu at home I got a message saying the UUID for root could not be found. By booting with the Ubuntu live CD I found that the C:\ubuntu\disks folder stat structure was broken, reported as "??? ??? ??" kinda thing. I booted into Windows, scheduled a CHKDSK, ran that on boot which found some errors and rebooted. Still no dice. I am not stressed because it appears my home directory is still there with all my content so I don't mind re-installing the OS (probably will clean it up some). What is the best path from here to repair the WUBI installation? Is there anything else I should do to repair it? I'm looking at whether the drive is dying now to work out why this occured. Possibly I moved the laptop before shutdown had completed.

    Read the article

  • Cygwin file and directory user and group

    - by dvanaria
    I use Cygwin as my main development environment on both my home and work computers. In order to share files between the two computers, I use Dropbox, which is installed in the following folder on both computers: c:\cygwin\home\dvanaria\dropbox Everything works great, except for one thing. When I'm working on my home computer and do an ls -l on any directory, all the files show up as owned by dvanaria of group Users. But when I work from my work computer, an ls -l shows all files as being owned by Administrators and of group Domain Users. I know Cygwin uses some kind of mapping between Windows users and permissions to the /etc/passwd file. But to be honest I have no idea how this file works or how it maps to Windows under Cygwin. Could anyone help figure this out? The main problem is that I can't edit any files when using my work computer, only read them.

    Read the article

  • Use crontab scheduling java application problem occurs

    - by koma
    The main method to start the java application. The main method initialize the log, and then determine whether the process is running. Every 10 minutes, scheduled to run through the linux crontab. Able to determine that the 10 minutes of this program must end. Under normal circumstances, will print the following log The beginning of the implementation of 10 minutes The end of the 10 minutes of normal The beginning of the implementation of 20 minutes The end of the 20 minutes of normal The beginning of the implementation of 30 minutes The end of the 30 minutes of normal ..... But now this situation: The beginning of the implementation of 10 minutes The end of the 10 minutes of normal Execution starts in 30 minutes, but detected already have a process in operation, the program exits. Start the execution of 40 points, but detected already have a process in operation, the program exits. ..... Very strange 20-minute log does not print, but the 20-minute program has been launched by the ps-ef | grep java view java thread, found in a 20-minute thread is locked. But why not see the log Check the linux dispatch log, not see scheduling a 20-minute log.

    Read the article

  • Is version history really sacred or is it better to rebase?

    - by dukeofgaming
    I've always agreed with Mercurial's mantra, however, now that Mercurial comes bundled with the rebase extension and it is a popular practice in git, I'm wondering if it could really be regarded as a "bad practice", or at least bad enough to avoid using. In any case, I'm aware of rebasing being dangerous after pushing. OTOH, I see the point of trying to package 5 commits in a single one to make it look niftier (specially at in a production branch), however, personally I think would be better to be able to see partial commits to a feature where some experimentation is done, even if it is not as nifty, but seeing something like "Tried to do it way X but it is not as optimal as Y after all, doing it Z taking Y as base" would IMHO have good value to those studying the codebase and follow the developers train of thought. My very opinionated (as in dumb, visceral, biased) point of view is that programmers like rebase to hide mistakes... and I don't think this is good for the project at all. So my question is: have you really found valuable to have such "organic commits" (i.e. untampered history) in practice?, or conversely, do you prefer to run into nifty well-packed commits and disregard the programmers' experimentation process?; whichever one you chose, why does that work for you? (having other team members to keep history, or alternatively, rebasing it).

    Read the article

  • What to have in sources.list on an Ubuntu LTS server (production)?

    - by nbr
    I have several Ubuntu 10.04 LTS servers in production and I'm using apticron to check that my software is up to date, security-wise. However, by default, Ubuntu has the lucid-updates repository enabled. This means lots of low-priority updates (such as this) that I don't need and thus, extra work for me. Is it okay to just remove the lucid-updates line(s) in sources.list? I still get security updates via lucid-security, right? So, this is what my sources.list would look like. deb http://se.archive.ubuntu.com/ubuntu/ lucid main restricted deb http://se.archive.ubuntu.com/ubuntu/ lucid universe deb http://security.ubuntu.com/ubuntu lucid-security main restricted deb http://security.ubuntu.com/ubuntu lucid-security universe

    Read the article

  • Limit WSUS replication to only certain product classifications

    - by MDMarra
    I have four WSUS 3.0 SP2 servers that are geographically distributed. The server at our main site (we'll call it WSUS1), is the main WSUS server. All manual and auto-approvals happen here. The other three WSUS servers are replicas of this server. Currently, we are only controlling desktop OS updates through WSUS. I would like to control server OS updates through WSUS as well. There is no need for all of these server updates to be on WSUS servers at the remote sites. The only server that would need a copy of them is WSUS1. Is there a way to keep my current infrastructure as-is and add server OS updates only to WSUS1, even though the others are set up as replicas, or will I need to configure an additional WSUS server that's not replicated?

    Read the article

  • Quitting a small start-up where you are a primary developer?

    - by programmx10
    Just curious to hear from other people who may have been in similar situations. I work for a small startup (very small) where I am the main developer for a major part of the app they are building, the other dev they have does a different area of work than I do so couldn't take over my part. I've been with the company 5 months, or so, but I am looking at going to a more stable company soon because its just getting to be too much stress, overtime, pressure, etc for too little benefit and I miss working with other developers who can help out on a project. The guy is happy with my work and I think I've helped them get pretty far but I've realized I just don't like being this much "on the edge" as its hard to tell what the direction of the company is going to be since its so new. Also, even though I'm the main dev for the project, I would still only consider myself a mid-level dev and am selling myself as such for the new job search. Just to add more detail, I'm not a partner or anything in the company and this was never discussed, so I just work on a W2 (with no benefits of course). I work at home so that makes it easier to leave, I guess, but I don't want to just screw the guy over but also don't want to be tied in for too long. Obviously I would plan to give 2 weeks notice at least, but should I give more? How should I bring up the subject because I know its going to be a touchy thing to bring up. Any advice is appreciated UPDATE: Thanks everyone for posting on this, I have now just completed the process of accepting an offer with a larger company and quitting the startup. I have given 2 weeks notice and have offered to make myself available after that if needed, basically its a really small company at this point so it would only be 1 dev that I would have to deal with... anyways, it looks like it may work out well as far as me maintaining a good relationship with the founder for future work together, I made it out to be more of a personal / lifestyle issue than about their flaws / shortcomings which definitely seems to help in leaving on a good note

    Read the article

  • Advice on off-site backup of Hyper-V Failover Cluster

    - by Paul McCowat
    We are currently setting up a Server 2008 R2 which will be off-site over a leased line with VPN. At the main site is 2 x Hyper-V hosts in a failover cluster with PowerVault M3000i iSCSI SAN. We are using BackupAssist for local backups and each host backups up itself and it's guests nightly creating a 500GB backup each which is copied to a 2TB rotated NAS drive. Files and SQL DB's are also backed up / log shipped etc. Looking for the best way to backup the Hyper-V VM's and copy them off-site so that the OS's are only a month old and the data is a day old. The main backups are too large to transfer between backups so options discussed so far are: Take rotating individual backups of the VM's each day and copy over, Day 1 SQL VM, Day 2 Exchange VM etc, would require more storage. Look in to Hyper-V snapshots, however don't believe these are supported in clustering. 3rd party replication tools

    Read the article

  • Cannot read/write a second drive in MBP 13

    - by Carlos
    I changed my original HDD for a SDD earlier this year and I just got one more SSD for my MBP 13 (2012) that I used to replace DVD drive. I'm using Mountain Lion. The SSD looks to be recognized allright, but I can't format it. Then I removed the main drive and tried the new one as the main drive and did the boot using a USB drive with MAC OS and everyhing worked as it should (like I just had one drive). However when I bring the first drive back together with the second they both show up but I can't use it. Seems like I have no permission, but when I look at it's properties it says I can read and write to it. Any ideas? Thanks a lot!

    Read the article

  • How can I render a semi transparent model with OpenGL correctly?

    - by phobitor
    I'm using OpenGL ES 2 and I want to render a simple model with some level of transparency. I'm just starting out with shaders, and I wrote a simple diffuse shader for the model without any issues but I don't know how to add transparency to it. I tried to set my fragment shader's output (gl_FragColor) to a non opaque alpha value but the results weren't too great. It sort of works, but it looks like certain model triangles are only rendered based on the camera position... It's really hard to describe what's wrong so please watch this short video I recorded: http://www.youtube.com/watch?v=s0JqA0rZabE I thought this was a depth testing issue so I tried playing around with enabling/disabling depth testing and back face culling. Enabling back face culling changes the output slightly but the problem in the video is still there. Enabling/disabling depth testing doesn't seem to do anything. Could anyone explain what I'm seeing and how I can add some simple transparency to my model with the shader? I'm not looking for advanced order independent transparency implementations. edit: Vertex Shader: // color varying for fragment shader varying mediump vec3 LightIntensity; varying highp vec3 VertexInModelSpace; void main() { // vec4 LightPosition = vec4(0.0, 0.0, 0.0, 1.0); vec3 LightColor = vec3(1.0, 1.0, 1.0); vec3 DiffuseColor = vec3(1.0, 0.25, 0.0); // find the vector from the given vertex to the light source vec4 vertexInWorldSpace = gl_ModelViewMatrix * vec4(gl_Vertex); vec3 normalInWorldSpace = normalize(gl_NormalMatrix * gl_Normal); vec3 lightDirn = normalize(vec3(LightPosition-vertexInWorldSpace)); // save vertexInWorldSpace VertexInModelSpace = vec3(gl_Vertex); // calculate light intensity LightIntensity = LightColor * DiffuseColor * max(dot(lightDirn,normalInWorldSpace),0.0); // calculate projected vertex position gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } Fragment Shader: // varying to define color varying vec3 LightIntensity; varying vec3 VertexInModelSpace; void main() { gl_FragColor = vec4(LightIntensity,0.5); }

    Read the article

  • Accessing localhost:8080 through local network

    - by Theron Luhn
    I'm developing a Python WSGI website. I'm running a Paste development server on my Mac (OS X 10.7) on port 8080. I want to test the website on some other devices and OSs I have connected to the local network (Windows 7 VM, iPad, iPhone, etc.), but am having trouble. I turned on Web Sharing, and am able to access that (port 80) without a problem on all my devices. Port 8080 still doesn't work. An excerpt from my Paste configuration: [server:main] use = egg:waitress#main host = 127.0.0.1 port = 8080 The OS X firewall (Settings - Security - Firewall) is off. I have no other firewall software installed. My network is through a Linksys WRT160N router. I haven't done much with the settings, so most of them are at their defaults. I've been Googling all morning, but can't find a solution.

    Read the article

  • Reasons behind polymorphism related behaviour in java

    - by Shades88
    I read this code somewhere class Foo { public int a; public Foo() { a = 3; } public void addFive() { a += 5; } public int getA() { System.out.println("we are here in base class!"); return a; } } public class Polymorphism extends Foo{ public int a; public Poylmorphism() { a = 5; } public void addFive() { System.out.println("we are here !" + a); a += 5; } public int getA() { System.out.println("we are here in sub class!"); return a; } public static void main(String [] main) { Foo f = new Polymorphism(); f.addFive(); System.out.println(f.getA()); // SOP 1 System.out.println(f.a); // SOP 2 } } For SOP1 we get answer 10 and for SOP2 we get answer 3. Reason for this is that you can't override variables whereas you can do so for methods. This happens because type of the reference variable is checked when a variable is accessed and type of the object is checked when a method is accessed. But I am wondering, just why is it that way? Can anyone explain me what is the reason for this behaviour

    Read the article

< Previous Page | 148 149 150 151 152 153 154 155 156 157 158 159  | Next Page >