Home Man
Today's Posts

Post questions about C, C++, Java, SQL, and other programming languages here.

Java static code


Login to Reply

Thread Tools Search this Thread
# 1  
Old 03-08-2018
Java static code

HI All

I am new to java in below code I am not able to understand the below line of code

the complete code is mentioned as below
class Student9{  
int rollno;  
String name;  
static String college = "ITS";  
static void change(){  
college = "BBDIT";  
  Student9(int r, String n){  
 rollno = r;  
 name = n;  
  void display (){System.out.println(rollno+" "+name+" "+college);}  
 public static void main(String args[]){  
 Student9 s1 = new Student9 (111,"Karan");  
Student9 s2 = new Student9 (222,"Aryan");  
Student9 s3 = new Student9 (333,"Sonoo");  

Moderator's Comments:
Java static code Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-08-2018 at 11:12 AM.. Reason: Added CODE tags.
# 2  
Old 03-08-2018
In a class, if you declare a method as static, you need not instantiate the class to be able to use the method. So , in your program, the method change() is being called directly by qualifying it with the class name.

You can read more in this link.
The Following User Says Thank You to balajesuri For This Useful Post:
dodona (03-18-2018)
# 3  
Old 04-22-2018
What bala is saying,

because not only change(), but also college, are static, they are class methods/variables rather than instance (object) methods/variables.

That means "college" will be changed for the entire class, not just for a single instance (object).
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with a Java code faizlo Programming 4 01-20-2014 10:14 PM
Block of code replacement in Java source code through Unix script hareeshram Shell Programming and Scripting 2 01-30-2012 10:54 AM
Even the Static cURL Library Isn't Static BrandonShw Programming 8 07-08-2011 11:57 AM
Static code analysis for Perl figaro UNIX for Advanced & Expert Users 2 05-27-2011 01:17 PM
can i have an optimal solution for this java code ? Facing Java heap space problem even at 3GB heaps vaibhavkorde Programming 2 04-12-2011 01:51 AM
Help with splitter code in JAVA eel Programming 1 09-19-2010 09:00 AM
Help with PrintWriter code in JAVA eel Programming 1 09-18-2010 06:42 AM
Help with Java code eel Programming 0 09-13-2010 10:37 AM
Compile & Run Java Code tguillea UNIX for Dummies Questions & Answers 4 05-28-2010 04:59 PM
I need HELP to Set up Coyote Linux router with 1 static IP & 64 internal static IP dlwoaud IP Networking 0 12-21-2009 04:01 AM

All times are GMT -4. The time now is 02:29 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
Show Password