Unix/Linux Go Back    

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

Java static code


Thread Tools Search this Thread Display Modes
Old Unix and Linux 1 Week Ago   -   Original Discussion by scriptor
scriptor's Unix or Linux Image
scriptor scriptor is offline
Registered User
Join Date: Jul 2012
Last Activity: 9 March 2018, 2:44 AM EST
Posts: 165
Thanks: 18
Thanked 0 Times in 0 Posts
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; 1 Week Ago at 11:12 AM.. Reason: Added CODE tags.
Sponsored Links
Old Unix and Linux 1 Week Ago   -   Original Discussion by scriptor
balajesuri's Unix or Linux Image
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
Join Date: Apr 2009
Last Activity: 9 March 2018, 11:32 PM EST
Location: India
Posts: 1,984
Thanks: 31
Thanked 575 Times in 548 Posts
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 (1 Day Ago)
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
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
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 03:42 PM.