You are on page 1of 2

Java Class Example Class in Java Example Program Java Class Example - Class in Java Example Program.

You can find Source code for Class in Java. Java Class Example Class in Java Example Program. You can find Source code for C lass in Java. class Student{ int rollNumber = 101; String name = eshusoft ; void setStudent(int rno,String sname){ rollNumber=rno; name=sname; } void display(){ System.out.println( rollNumber = +rollNumber); System.out.println( name = +name); } } public class ClassDemo { public static void main(String[] args) { Student obj = new Student(); System.out.println( student object is created ); System.out.println( Roll Number: + obj.rollNumber); System.out.println( Name: + obj.name); obj.display(); obj.setStudent(201, eshusoft123?); System.out.println( student object is created ); System.out.println( Roll Number: + obj.rollNumber); obj.display(); } } Result: student object is created Roll Number:101 Name:eshusoft rollNumber =101 name =eshusoft Inheritance Example Program in Java Inheritance Example Program in Java. You can find inheritance example program (c ode snippets) in this page. Inheritance Example Program in Java. You can find inheritance example program (c ode snippets) in this page. class Base{ private int num; public Base(){ num = 100; System.out.println( \n\tDefault constructor of Base class. ); } public void displayNum(){ System.out.println( \n\tValue of num: + num); } } class Derived extends Base{ private int data; public Derived(){ data = 200; System.out.println( \n\tDefault constructor of Derived class. ); } public void displayData(){

System.out.println( \n\tValue of data: } } public class InheritanceDemo{ public static void main(String args[]) { Derived ob = new Derived(); ob.displayNum(); ob.displayData(); } } Result: Default constructor of Base class. Default constructor of Derived class. Value of num: 100 Value of data: 200

+ data);

You might also like